I have an Excel Macro as follows:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim i&, j&, k&, LR_A&, LR_B&, LR_C&, count&
LR_A = Range("A" & Rows.count).End(xlUp).Row
LR_B = Range("B" & Rows.count).End(xlUp).Row
LR_C = Range("C" & Rows.count).End(xlUp).Row
count = 1
For i = 1 To LR_A
For j = 1 To LR_B
For k = 1 To LR_C
Range("D" & count).Value = Range("A" & i).Value
Range("E" & count).Value = Range("B" & j).Value
Range("F" & count).Value = Range("C" & k).Value
count = count + 1
Next k
Next j
Next i
Application.ScreenUpdating = True
End Sub
As you can see, it is resorting the data in columns A, B, and C into D, E, and F.
What code do I need to add to get it to ignore the column headers in A, B, and C? I have searched around but have been unable to find an answer.
In addition, how would I change it so that it instead of resorting the data into D, E, and F, it is resorting it into A, B, and C on another worksheet?
This is my first macro, so they are pretty basic questions.
Thanks in advance
Answer to your question
To avoid copying the headers, you should begin your loops at index
2.To copy values to another
Worksheet, you need to call it in yourRange.Maybe a better way to handle this case
Looping over range using index can be very slow.
I advise you to have a look at this link: http://www.ozgrid.com/VBA/VBALoops.htm where the author explained faster ways to loop over ranges.
Some tips
Have a look at Excel
SpecialCellsas described here.For instance, in your case, you could try to use
ActiveSheet.UsedRangeinstead of finding the last used row.