dagonet
Computer
- Mar 26, 2008
- 3
So it's probably obvious that I am a newbie by looking at my code. Why doesn't this work? What should I do to fix?
In this example I use the Excel Formula in C3 =CountA(Sheet2!A:A), which returns the value of 11 (number of rows not empty), which includes Headers.
I want to copy the Range on Sheet2 (A2:F11) because the count told me 11 rows to Sheet1 (A2:F11)
Dim MyCount = Integer
Dim i = Integer
Sub do_it()
MyCount = Sheets("Sheet1").Cells(C, 3)
For i = 2 To MyCount
Sheets("Sheet1").Cells(A, i) = Sheets("Sheet2").Cells(A, i)
Sheets("Sheet1").Cells(B, i) = Sheets("Sheet2").Cells(B, i)
Sheets("Sheet1").Cells(C, i) = Sheets("Sheet2").Cells(C, i)
Sheets("Sheet1").Cells(D, i) = Sheets("Sheet2").Cells(D, i)
Sheets("Sheet1").Cells(E, i) = Sheets("Sheet2").Cells(E, i)
Sheets("Sheet1").Cells(F, i) = Sheets("Sheet2").Cells(F, i)
Next i
End Sub
In this example I use the Excel Formula in C3 =CountA(Sheet2!A:A), which returns the value of 11 (number of rows not empty), which includes Headers.
I want to copy the Range on Sheet2 (A2:F11) because the count told me 11 rows to Sheet1 (A2:F11)
Dim MyCount = Integer
Dim i = Integer
Sub do_it()
MyCount = Sheets("Sheet1").Cells(C, 3)
For i = 2 To MyCount
Sheets("Sheet1").Cells(A, i) = Sheets("Sheet2").Cells(A, i)
Sheets("Sheet1").Cells(B, i) = Sheets("Sheet2").Cells(B, i)
Sheets("Sheet1").Cells(C, i) = Sheets("Sheet2").Cells(C, i)
Sheets("Sheet1").Cells(D, i) = Sheets("Sheet2").Cells(D, i)
Sheets("Sheet1").Cells(E, i) = Sheets("Sheet2").Cells(E, i)
Sheets("Sheet1").Cells(F, i) = Sheets("Sheet2").Cells(F, i)
Next i
End Sub