多列数据区域转换成一列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

相关文章
·十秒免工具激活windows 1002-25
·word排版技巧整理08-02
·批量修改PPT字体和颜色的方法09-20
·堪称「神器」的电脑软件/网站02-13
·word文档单词自动加音标的宏代码11-04
·SQL SERVER数据库中快速找主表11-10
·FinalData恢复在数码相机误删的相片08-07
·巧用Excel数组公式统计各班优秀人数04-24
·Windows 7将数据保存为虚拟磁盘文件11-22
·WDS无线组网、无线桥接的应用01-13
最新文章
阅读排行