Compile Error: Next without For

Cazzl

New Member
Joined
Sep 27, 2011
Messages
3
I am not sure why this does not work, I get the error message Next without For, but it seemed to be working fine last time I used the sheet and am not aware that I have changed anything, so any help would be greatly appriciated! This is my code:

Private Sub ComboBox1_Change()

'check if monday choosen
If Weekday(Calendar1.Value, vbMonday) <> 1 Then
MsgBox ("Please choose a Monday")
Exit Sub
End If

'set report adjustment factor
If TextBox1.Value = 1 Then

ElseIf TextBox1.Value = 2 Then
rep2 = 20
ElseIf TextBox1.Value = 3 Then
rep3 = 44
ElseIf TextBox1.Value = 4 Then
rep2 = 20
rep3 = 44
End If

'set sheet names
Set Db = Sheets("Dive_Load_Database")
Set Rp = Sheets("Report")

'clear past data
Rp.Range(Cells(7 + rep3, 2 + rep2), Cells(13 + rep3, 19 + rep2)).ClearContents
Rp.Range(Cells(16 + rep3, 2 + rep2), Cells(22 + rep3, 10 + rep2)).ClearContents




'set unique ID
UniqueID = ComboBox1.Value & Calendar1.Value + wkday

'find unique ID
Set c = Db.Range("A:A").Find(UniqueID)

'skip if no data
If c Is Nothing Then
GoTo Nodata
End If

'set row of current data
Drow = c.Row

'find days summary data
Set Sumloc = Db.Rows(Drow).Find("Summary")

'set column of summary
DClm = Sumloc.Column

'get week summary values
For sumv = 1 To 18

Rp.Cells(7 + wkday + rep3, sumv + 1 + rep2).Value = Db.Cells(Drow, DClm + sumv)

Next sumv

'find days wellbeing data
Set Sumloc2 = Db.Rows(Drow).Find("Well-Being")

'set column of wellbeing
DClm2 = Sumloc2.Column

'get week wellbeing values
For sumv2 = 1 To 18

Rp.Cells(16 + wkday + rep3, sumv2 + 1 + rep2).Value = Db.Cells(Drow, DClm2 + sumv2)

Next sumv2

Nodata:

Next wkday

Sheets("Report").Cells(4 + rep3, 1 + rep2).Value = ComboBox1.Value
Sheets("Report").Cells(4 + rep3, 12 + rep2).Value = Calendar1.Value

ChooseNameReport.hide
Unload Me




End Sub




The Next wkday (near the bottom)is highlighted when the error message comes up. Any ideas?

Thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Welcome to the Board!

The error message and the highlighted code are telling you exactly what the problem is. You have a "Next wkday" statement, without the corresponding "For" statement in your code. Every For loop needs a Next statement, and vice versa. So the number of "For" and "Next" statements should be the same.
 
Upvote 0
Is part of the code missing?

You don't seem to have loop corresponding to Next wkday, or even a variable called wkday.
 
Upvote 0
Thanks for the reply, I'm just not quite sure where I need to put the "For" and what I have to write with it? sorry i'm quite new to this!!
 
Upvote 0
That is all the code I have. This sheet got passed onto me and I have not changed any of the code, it was working, but now seems to have stopped!! Not sure if someone has accidently deleted some when they have been looking at the sheet?? Is it relatively easy to add in the missing loop etc? thanks
 
Upvote 0
The code, as currently written, would not work at all, as it would have compile errors like you are experiencing. Something must have been changed from any version that was working. Can you obtain a backup or a copy of the original?

Debugging other people's code can be difficult. Without really understanding exactly what the code is supposed to be doing, and the structure of the data you are working with, it could be a bit tricky trying to fix it. You obviously need a "For" statement in there, but the question is where, and what are the "bounds" on it?

My suggestion would be to try to first obtain the original code, or contact the person who wrote it.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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