多列数据区域转换成一列VBA代码


来源:网络整理
发布时间:2019-03-05 00:07:00
查看次数:

内容提要:VBA模块,实现了选择需要转换的数据区域和选择存放区域起始单元格。

Sub rangetoonecol2()
Dim TheRng, TempArr, RNG As Range
Dim i As Integer, j As Integer, elemCount As Integer
On Error Resume Next
Set RNG = Application.InputBox("请选择源区域", "区域转一列", , , , , , 8)
If RNG.Cells.Count = 1 Then
    MsgBox "所选择区域单元格个数应该大于1"
    Exit Sub
Else
  TheRng = RNG
  elemCount = UBound(TheRng, 1) * UBound(TheRng, 2)
  ReDim TempArr(1 To elemCount, 1 To 1)
  For i = 1 To UBound(TheRng, 1)
    For j = 1 To UBound(TheRng, 2)
      TempArr((i - 1) * UBound(TheRng, 2) + j, 1) = TheRng(i, j)
    Next
  Next
 Set RNG = Application.InputBox("请选择存放区域起始单元格", "区域转一列", , , , , , 8)
  RNG(1).Resize(elemCount, 1) = TempArr
End If
End Sub

相关文章
·Excel 如何只保护部分单元格05-08
·PS如何一键批量裁剪图片?06-02
·word排版技巧整理08-02
·隐藏Excel错误结果显示的三种方法10-12
·使用光影魔术手修改相片格式教程10-29
·VBA撤销excel工作表保护09-01
·快速创建以当前日期命名的文件夹05-15
·excel删除数字保留文本02-04
·解决gmail不稳定的方法03-17
·发送手机文件到电脑的方法11-01
最新文章
阅读排行