excel - 需要 Excel VBA 将 B、C、D 列复制到 A 列
解决方案
我建议以下代码:
Sub consolidateColumns()
Dim lr As Long, lr2 As Long
With ActiveSheet 'Replace with the worksheet you need, avoid using ActiveSheet
lr = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To 3 'Adjust the 3 to however many columns you need
lr2 = .Cells(Rows.Count, i).End(xlUp).Row
.Range(.Cells(1, i), .Cells(lr2, i)).Cut .Cells(lr + 1, 1)
lr = lr + lr2
Next i
End With
Application.CutCopyMode = False
End Sub
为了使其更短,但一开始更难阅读,您还可以使用以下代码:
Sub consolidateColumns()
With ActiveSheet 'Replace with the worksheet you need, avoid using ActiveSheet
For i = 2 To 3 'Adjust the 3 to however many columns you need
.Range(.Cells(1, i), .Cells(.Cells(Rows.Count, i).End(xlUp).Row, i)).Cut .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
Next i
End With
Application.CutCopyMode = False
End Sub
推荐阅读
- google-bigquery - 如何使用 Google 工具和 JavaScript 存储和提供优惠券
- c++ - 任何人都可以在 switch 语句上方解释这个函数定义吗?
- java - Netbeans java jar 与 javadocs 和源使用 xml 和属性文件
- java - 如何通过端口转发在 Internet 上使用 SSL 部署 MQTT?
- python - 排名线图定制
- python - 如何在 Python 中计算类变量?
- java - 无法使用外部类按降序对数组进行排序
- python - 破折号返回't.split 不是函数'错误'
- javascript - 使用for await...of时如何获取key值
- r - 条形图中的意义线