一个城市的信仰

Excel 多列合并一列,10秒钟搞定它

Excel 多列合并一列,10秒钟搞定它,使用方法,在Excel里按alt+f11,插入-模块,把下面代码复制到模块里,直接关闭,然后在表格里按alt+f8,点执行,你就会看到新大陆!!!!!!完美解决!!!!!

Sub MergeDataToColumn()
Dim lastRow As Long, lastColumn As Long, newRow As Long
Dim i As Long, j As Long
Dim newData() As Variant

' 获取当前工作表的最后一行和最后一列
lastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lastColumn = Cells.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column

' 将数据存储到一个二维数组中
ReDim newData(1 To lastRow * lastColumn, 1 To 1)
newRow = 1
For i = 1 To lastRow
For j = 1 To lastColumn
newData(newRow, 1) = Cells(i, j).Value
newRow = newRow + 1
Next j
Next i

' 将数据写入新工作表的一列
With Worksheets.Add
.Name = "Merged Data"
.Range("A1").Resize(UBound(newData, 1), 1).Value = newData
End With

' 提示操作完成
MsgBox "数据已合并到新工作表。", vbInformation
End Sub
赞(0) 打赏
未经允许不得转载:东东博客 » Excel 多列合并一列,10秒钟搞定它

相关推荐

  • 暂无文章

评论 抢沙发