多列数据区域转换成一列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
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
- 最新文章
- ·视频号视频的四种下载方法07-07·Win10系统开机启动文件夹在哪里?04-16·十秒免工具激活windows 1002-25·批量替换word文档中的第一行作为文件的文件名06-21·连接打印机时需要输入用户名密码怎么办?05-15·免魔法使用 New Bing 新方案03-18·Win10电脑账号密码设置、修改、取消12-06
- 阅读排行
- ·如何让试题的ABCD选项对齐04-13·word排版技巧整理08-02·word 如何自动生成目录08-02·Excel 进行学生成绩统计分析03-13·我的电脑图标不见了,怎么找回来!09-14·不同电脑文件字体改变了的解决方法12-15·Win10电脑的一些安装提示12-03·Word高级替换技巧03-05·Excel如何批量插入分页符02-12·巧用Excel数组公式统计各班优秀人数04-24
2008-2024 | www.zshunj.cn |www.yykz.net
点击这里识别二维码关注公众号
点击这里识别二维码关注公众号