I had to solve an Excel problem with VBA today but i feel like a noob. My requirements are really simple But somehow I'm on the line.
I would like to add to each existing line, some variants on an additional sheet.
How is that possible? Can anyone help me pls?
Thanks for Feedback and your help.
Greetings eXocode
The Solution was:
`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`
Here's a simple way to do it; you will have to adjust the Ranges to your needs, but the basic algorithm should be what you are looking for:
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