Error with nested For...Next statements

jrfeni

New Member
Joined
Jun 27, 2005
Messages
18
When I try to run the following code, I get a "Next without For" error:

Sub update()

Dim i As Long
Dim j As Long
Dim rcount As Long
Dim Ws As Worksheet

For i = 1 To 12
Worksheets("Lookup").Cells(2, 3).Value = i
If i <= 9 Then
Set Ws = Sheets("LL0" & i)
ElseIf i = 12 Then
Set Ws = Sheets("LL14")
Else
Set Ws = Sheets("LL" & i)
With Ws
.Range("a4:c368").Clear
End With
For j = 1 To 3
rcount = Worksheets("Reference").Range.Cells(i, 3)
Worksheets("Lookup").Cells(5, 2).Value = j
Range("lookup_range").Copy
With Ws
.Cells(rcount, 1).PasteSpecial Paste:=xlPasteValues
End With
Next j
Next i

End Sub


Sorry if the formatting sucks. Can anyone tell me what the problem is?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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