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
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