我今天必须解决VBA的Excel问题,但我觉得自己像个菜鸟。我的要求非常简单但不知怎的,我在线。
我想在每个现有行中添加一些附加工作表上的变体。
怎么可能?任何人都可以帮我吗?
感谢您的反馈和帮助。
问候 eXocode
解决方案是:
`Sub CopyData()
RowInSheet3 = 1
For RowInSheet1 = 1 To Sheets(1).Range("A1").SpecialCells(xlCellTypeLastCell).Row
Sheets(3).Cells(RowInSheet3, 1) = Sheets(1).Cells(RowInSheet1, 1)
RowInSheet3 = RowInSheet3 + 1
For RowInSheet2 = 1 To Sheets(2).Range("A1").SpecialCells(xlCellTypeLastCell).Row
Sheets(3).Cells(RowInSheet3, 1) = Sheets(2).Cells(RowInSheet2, 1)
Sheets(3).Cells(RowInSheet3, 2) = Sheets(2).Cells(RowInSheet2, 2)
RowInSheet3 = RowInSheet3 + 1
Next
Next
结束Sub`
答案 0 :(得分:1)
这是一个简单的方法;您必须根据需要调整范围,但基本算法应该是您正在寻找的:
Sub CopyData()
RowInSheet3 = 1
For RowInSheet1 = 1 To Sheets(1).Range("A1").SpecialCells(xlCellTypeLastCell).Row
Sheets(3).Cells(RowInSheet3, 1) = Sheets(1).Cells(RowInSheet1, 1)
RowInSheet3 = RowInSheet3 + 1
For RowInSheet2 = 1 To Sheets(2).Range("A1").SpecialCells(xlCellTypeLastCell).Row
Sheets(3).Cells(RowInSheet3, 1) = Sheets(2).Cells(RowInSheet2, 1)
Sheets(3).Cells(RowInSheet3, 2) = Sheets(2).Cells(RowInSheet2, 2)
RowInSheet3 = RowInSheet3 + 1
Next
Next
End Sub