Reputation: 375
I am doing a simple loop code where I want Y to equal 10 and each time it goes through the loop to +1 i.e. 10,11,12,13
However I am getting compile errors on the variables X and Y if anyone could let me know why this is occuring it would be much appreciated.
Dim targetrow As Long
targetrow = ActiveSheet.Range("Total").Offset(-2, 0).Row
Y = 10
For X = 19 To targetrow Step 1
If Range("K" & X) <> "" Then
Range("K" & X).Copy
Workbooks(PtchFile).Activate
Range("G" & Y).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Y = Y + 1
X = X + 1
Else
End If
Next X
Upvotes: 1
Views: 66
Reputation: 73
declare your variable as following above your code snippet:
Dim X as Integer
Dim Y as Integer
You may also want do activate the workbook where you copy your range before you copy the range, at the next iteration it will copy the Range("K" & X+1) from the Workbook PtchFile
cheers.
Upvotes: 1