I have fixed 1 problem to face another.
Unfortunatley I am stuck and unaware of which way to go. I have highlighted the place it debugs below and the error is "For Control Variable in use" Is there anyway i can get around this. Also when i add the "next's" below the fault changes to "Block If without End If" Does this mean i have to have end if's to match If for each part of the VB. ie before gotcha i have 8 "If's" Do i need 8 "End If's" before it re loops?
Unfortunatley I am stuck and unaware of which way to go. I have highlighted the place it debugs below and the error is "For Control Variable in use" Is there anyway i can get around this. Also when i add the "next's" below the fault changes to "Block If without End If" Does this mean i have to have end if's to match If for each part of the VB. ie before gotcha i have 8 "If's" Do i need 8 "End If's" before it re loops?
Rich (BB code):
'Open file
Dim gotcha As Boolean
Workbooks.Open Filename:="C:\Users\MAZZA\Documents\Gavin\Car Park\FYvData.xls" 'Home
'Workbooks.Open Filename:="\\W2K6082\COMMON\SHARED\Gavin Mazza\Car Park\FYVData.xls"
Dim myBook As Workbook
On Error Resume Next
Set myBook = Application.Workbooks("FYVData.xls")
On Error GoTo 0
Dim iRow As Long
Dim ws As Worksheet
Dim lRow As Integer
Set ws = Worksheets("Sheet1")
If UserForm2.ComboBox1 = "Laura Haynes" Then
Pword = InputBox("Please enter password")
If Pword = "ticket" Then
ActiveWorkbook.Sheets("Laura Haynes").Activate
Else
MsgBox "Please contact your administrator for a password"
Workbooks("FYVData.xls").Close True
Exit Sub
End If
End If
Unload Me
lRow = Range("C" & Rows.Count).End(xlUp).Row
For Each cell In Range("C1:C" & lRow)
If cell.Value = ComboBox2.Value Then
For i = 3 To lRow
If Cells(i, 1).Value = "" Then Exit For
If Cells(i, 1).Value <> "" And Cells(i, 14).Value = "" Then
gotcha = True
UserForm1.Show False
UserForm1.txtdate.Value = Cells(i, 1)
UserForm1.TextBox1.Value = Cells(i, 3)
UserForm1.TextBox13.Value = Cells(i, 2)
UserForm1.TextBox2.Value = Cells(i, 4)
UserForm1.TextBox3.Value = Cells(i, 7)
UserForm1.TextBox6.Value = Cells(i, 5)
UserForm1.TextBox5.Value = Cells(i, 6)
UserForm1.TextBox4.Value = Cells(i, 8)
UserForm1.TextBox7.Value = Cells(i, 9)
UserForm1.TextBox8.Value = Cells(i, 10)
UserForm1.TextBox9.Value = Cells(i, 13)
UserForm1.TextBox14.Value = Cells(i, 11)
UserForm1.TextBox15.Value = Cells(i, 12)
UserForm1.TextBox11.Value = Cells(i, 4)
With UserForm1.CBoxAdd
.AddItem "Christopher Nicholls"
.AddItem "Craig Keevney"
.AddItem "Daniel Littler"
.AddItem "Dean Morrison"
.AddItem "Ian Travis"
.AddItem "Ian Wilshaw"
.AddItem "Jennifer Cheetham-Shaw"
.AddItem "Katrina Whiting"
.AddItem "Lindsey Dodds"
.AddItem "Martyn Bryan"
.AddItem "Sonia Jennings"
End With
With UserForm1.txtdate
.Enabled = False
End With
End If
Next i
If gotcha = False Then
MsgBox "Nothing to Update"
ActiveWindow.Close (True)
End If
End If
Next 'Removed ' before next and added next below in RED
gotcha = False
'If Louise Makin - callcentre enquiry
If UserForm2.ComboBox1 = "Sheet1" Then
Pword = InputBox("Please enter password")
If Pword = "judy" Then
ActiveWorkbook.Sheets("Louise Makin").Activate
Else
MsgBox "Please contact your administrator for a password"
Workbooks("FYVData.xls").Close True
Exit Sub
End If
Unload Me
lRow = Range("C" & Rows.Count).End(xlUp).Row
For Each cell In Range("C1:C" & lRow)
If cell.Value = ComboBox2.Value Then
For i = 3 To lRow
If Cells(i, 1).Value = "" Then Exit For
If Cells(i, 1).Value <> "" And Cells(i, 14).Value = "" Then
gotcha = True
UserForm1.Show False
UserForm1.txtdate.Value = Cells(i, 1)
UserForm1.TextBox1.Value = Cells(i, 3)
UserForm1.TextBox13.Value = Cells(i, 2)
UserForm1.TextBox2.Value = Cells(i, 4)
UserForm1.TextBox3.Value = Cells(i, 7)
UserForm1.TextBox6.Value = Cells(i, 5)
UserForm1.TextBox5.Value = Cells(i, 6)
UserForm1.TextBox4.Value = Cells(i, 8)
UserForm1.TextBox7.Value = Cells(i, 9)
UserForm1.TextBox8.Value = Cells(i, 10)
UserForm1.TextBox9.Value = Cells(i, 13)
UserForm1.TextBox15.Value = Cells(i, 12)
UserForm1.TextBox14.Value = Cells(i, 11)
UserForm1.TextBox11.Value = Cells(i, 4)
With UserForm1.CBoxAdd
.AddItem "Anthony Fox"
.AddItem "Ben Buckley"
.AddItem "Joanna Hanson"
.AddItem "Keith Drummond"
.AddItem "Linda Mason"
.AddItem "Lisa Bagulay"
.AddItem "Marie Lyons"
.AddItem "Norman Young"
.AddItem "Philip Stanistreet"
.AddItem "Rebecca Lees"
.AddItem "Samantha Ralph"
.AddItem "Tom Benson"
.AddItem "Tracy Carroll"
End With
With UserForm1.txtdate
.Enabled = False
End With
End If
Next i
If gotcha = False Then
MsgBox "Nothing to Update"
ActiveWindow.Close (True)
End If
End If
gotcha = False
Next
'If Lorraine Tinnion - callcentre enquiry
If UserForm2.ComboBox1 = "Sheet1" Then
Pword = InputBox("Please enter password")
If Pword = "sharples" Then
ActiveWorkbook.Sheets("Lorraine Tinnion").Activate
Else
MsgBox "Please contact your administrator for a password"
Workbooks("FYVData.xls").Close True
Exit Sub
End If
Unload Me
lRow = Range("C" & Rows.Count).End(xlUp).Row
For Each cell In Range("C1:C" & lRow)
If cell.Value = ComboBox2.Value Then
For i = 3 To lRow
If Cells(i, 1).Value = "" Then Exit For
If Cells(i, 1).Value <> "" And Cells(i, 14).Value = "" Then
gotcha = True
UserForm1.Show False
UserForm1.txtdate.Value = Cells(i, 1)
UserForm1.TextBox1.Value = Cells(i, 3)
UserForm1.TextBox13.Value = Cells(i, 2)
UserForm1.TextBox2.Value = Cells(i, 4)
UserForm1.TextBox3.Value = Cells(i, 7)
UserForm1.TextBox6.Value = Cells(i, 5)
UserForm1.TextBox5.Value = Cells(i, 6)
UserForm1.TextBox4.Value = Cells(i, 8)
UserForm1.TextBox7.Value = Cells(i, 9)
UserForm1.TextBox8.Value = Cells(i, 10)
UserForm1.TextBox9.Value = Cells(i, 13)
UserForm1.TextBox14.Value = Cells(i, 11)
UserForm1.TextBox15.Value = Cells(i, 12)
UserForm1.TextBox11.Value = Cells(i, 4)
With UserForm1.CBoxAdd
.AddItem "Alan Cotton"
.AddItem "Alex McQuarrie"
.AddItem "David Bowler"
.AddItem "Emma Coleman"
.AddItem "James Anthony Wood"
.AddItem "John O'Doherty"
.AddItem "Kirsten Hough"
.AddItem "Kurt Melia"
.AddItem "Luke Cunningham"
.AddItem "Mohsin Inam"
.AddItem "Paul Lunn"
.AddItem "Rabiha Younis"
.AddItem "Sarah Lloyd"
.AddItem "Sarah Whitehead"
End With
With UserForm1.txtdate
.Enabled = False
End With
End If
Next i
If gotcha = False Then
MsgBox "Nothing to Update"
ActiveWindow.Close (True)
End If
End If
Next
End Sub
Last edited: