我需要帮助。我有几张 2007 工作表,其中包含两列数据和多行。我想获取 B 列每行中的信息并将其添加/移动为 A 列下的新行。使用 VBA 可以做到这一点吗?换句话说,我不想有两列。归根结底,我希望所有内容都在一列中。如果是这样,有人可以帮忙吗?示例(当前工作表):
Column A-------------- Column B
What's today?--------- Tuesday
What is this? ---------- It's an apple
What's your name?----My name is Mike
预期结果(中间不应有空行)
Column A
What's today?
Tuesday
What is this?
It's an apple
What's your name?
My name is Mike
答案1
您可以尝试以下 VBA 代码。它插入一个新行,然后将 B 列的值剪切并粘贴到 A 列中新插入的行。
Sub CutAndPaste()
Dim LastRow As Long
'Get last row with data
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
'Row counter
Dim i As Integer
'Counter to start at 2nd row
i = 2
For x = 1 To LastRow
'Insert new row
ActiveSheet.Cells(i, 1).Insert (xlShiftDown)
'Cut and paste value from column B to inserted cell in column A
Range("B" & x).Cut Range("A" & i)
'Increase counter
i = i + 2
Next
End Sub