Invalid Next reference

VBA_Noob002

New Member
Joined
Mar 29, 2016
Messages
5
Hi Guys, I get an invalid Next control variable reference for the below code, please advise
Code:
Sub TRP()




Dim X As Long
Dim Y As Long




For X = 1 To 32
For Y = 1 To 32




With Workbooks("TB.xlsx").Worksheets("XM").Range(Cells(112, X + 2), Cells(112, X + 4)).Copy


End With




With Workbooks("HB.xlsm").Worksheets("XMR").Range(Cells(Y + 1, X + 3), Cells(Y + 1, X + 5)).Select
ActiveSheet.PasteSpecial Paste:=xlValues, Operation:=xlNone, Skipblanks:=False, Transpose:=False




End With


Next X
Next Y




End Sub
 
Last edited by a moderator:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the forum.

You have to close the loops in the reverse order to how you started them, so your Next Y should be before the Next X.
 
Upvote 0

Forum statistics

Threads
1,216,471
Messages
6,130,823
Members
449,595
Latest member
jhester2010

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top