VBA - Invalid next control variable reference

Tflex88

New Member
Joined
Jul 17, 2007
Messages
22
I keep getting the Invalid next control variable reference error on my macro. I am just trying to copy certain cells and then paste them down a row. The code is below. Any help would be greatly appreciated.

Sub ForecastPYupdate()
'
' ForecastPYupdate Macro
' Macro recorded 7/2/2008 by Rich Products Corp.
'

'
For I = 4 To 2000
For J = 9 To 20
If Cells(I, 1) = 1 And Cells(1, J) = 1 Then
Cells(I, J) = Selection.Copy
Cells(I + 1, J) = Selection.Paste
Next I
End If
End Sub
 
I rectified my ERROR.
Thanks a lot Sir for your quick proactive response.

Regards,
Manoj
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Sir,

As we know tp get the current month detail, code is

Format(Now(), "MMM-YYYY")


Similarly I want to the code to get the previous month.

Plz Help
 
Upvote 0
wh8mbs3rkqau5ojih97a_thumb.jpg
 
Upvote 0
You also need to move your End If up:

End If
Next J
Next I

Your If construct is inside the J loop.

I get the same error also but I am trying to use the same for...next loop on the same rows (8 to 22) but different columns ( columns 8 and then 23) and I want to change the font red under the specified condition. I use the same counters as above (i and j). How do I accomplish this:
code:

For i = 8 To 22
If Cells(i, 8).Value <= 69 Then
Cells(i, 8).Resize.Font.ColorIndex = 3

For j = 8 To 22
If Cells(j, 23).Value <= 69 Then
Cells(j, 23).Resize.Font.ColorIndex = 3
End If

Next j
Next i
 
Upvote 0
It's:

Rich (BB code):
For i = 8 To 22
    If Cells(i, 8).Value <= 69 Then
        Cells(i, 8).Resize.Font.ColorIndex = 3
    End If
Next i
For j = 8 To 22
    If Cells(j, 23).Value <= 69 Then
        Cells(j, 23).Resize.Font.ColorIndex = 3
    End If
Next j
<!-- / message -->
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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