Hi,
I am having the following syntax error in VBA and I am not sure what the correct syntax is:
Sheet1
<tbody>
</tbody>
So I want to copy the above into sheet2 in VBA. This is straightforward if I use range (A1:A6) and range (A1:F1), but I want to do it more dynamic by using last-column and last-row.
At this moment I have the following code:
Sub test()
Dim lRow As Long
Dim lCol As Long
lRow = Cells(Rows.Count, 1).End(xlUp).Row
lCol = Cells(1, Columns.Count).End(xlToLeft).Column
Worksheets("Ark1").Range("A1:A" & lRow).Copy Worksheets("Ark2").Range("A1:A" & lRow)
Worksheets("Ark1").Range("A1:" & lCol??).Copy Worksheets("Ark2").Range("A1:" & lCol??)
End Sub
Ark1 = sheet1 and Ark2 = sheet2 (I am using a danish version of Excel)
So the code is able to copy (A1:A6) from sheet1 into (A1:A6) in sheet2, but I am not sure on how to set the columns up. What is the syntax here? The variable lcol in the example above is only F right and not F1??
Any suggestion?
Thanks!!
I am having the following syntax error in VBA and I am not sure what the correct syntax is:
Sheet1
Date | Com1 | Com2 | Com3 | Com4 | Com5 |
Date1 | |||||
Date2 | |||||
Date3 | |||||
Date4 | |||||
Date5 |
<tbody>
</tbody>
So I want to copy the above into sheet2 in VBA. This is straightforward if I use range (A1:A6) and range (A1:F1), but I want to do it more dynamic by using last-column and last-row.
At this moment I have the following code:
Sub test()
Dim lRow As Long
Dim lCol As Long
lRow = Cells(Rows.Count, 1).End(xlUp).Row
lCol = Cells(1, Columns.Count).End(xlToLeft).Column
Worksheets("Ark1").Range("A1:A" & lRow).Copy Worksheets("Ark2").Range("A1:A" & lRow)
Worksheets("Ark1").Range("A1:" & lCol??).Copy Worksheets("Ark2").Range("A1:" & lCol??)
End Sub
Ark1 = sheet1 and Ark2 = sheet2 (I am using a danish version of Excel)
So the code is able to copy (A1:A6) from sheet1 into (A1:A6) in sheet2, but I am not sure on how to set the columns up. What is the syntax here? The variable lcol in the example above is only F right and not F1??
Any suggestion?
Thanks!!