Hi,
I have created a UserForm that adds forecasted staff in post figures to specified columns in a spreadsheet and also allows the user to view and edit any existing figures.
It identifies the correct row to put the data in by looking at the Job Type that has been selected in the JobListBox.
There are 132 rows with one different job type per row on the sheet (no new rows can be added), and the UserForm works perfectly until it gets to Row 112 - any job type on row 112-132 that is selected will have the figures entered randomly in different rows, even though the figures go to the correct place for all the job types on the previous rows.
I can't work out why this is happening - can anyone help? The sheet is sheet 2 (of 2) in the workbook, and is named 'Overview'. My code is below:
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub ClearButton_Click()
Call UserForm_Initialize
End Sub
Private Sub JobListBox_Click()
'Event handler when an entry is selected in the JobListBox, shows existing values
With Sheets(2)
dataRow = WorksheetFunction.Match(JobListBox.Value, .Range("A:A"))
Apr14TextBox.Value = .Cells(dataRow, 5).Value
Jul14TextBox.Value = .Cells(dataRow, 8).Value
Oct14TextBox.Value = .Cells(dataRow, 11).Value
Jan15TextBox.Value = .Cells(dataRow, 14).Value
Apr15TextBox.Value = .Cells(dataRow, 15).Value
Apr16TextBox.Value = .Cells(dataRow, 16).Value
Apr17TextBox.Value = .Cells(dataRow, 17).Value
Apr18TextBox.Value = .Cells(dataRow, 18).Value
ReasonTextBox.Value = .Cells(dataRow, 19).Value
End With
End Sub
Private Sub OKButton_Click()
'Data transfer - instructs Excel on where to put the values entered in text boxes
Dim dataRow As Long
With Sheets(2)
dataRow = WorksheetFunction.Match(JobListBox.Value, .Range("A:A"))
.Cells(dataRow, 5).Value = Apr14TextBox.Value
.Cells(dataRow, 8).Value = Jul14TextBox.Value
.Cells(dataRow, 11).Value = Oct14TextBox.Value
.Cells(dataRow, 14).Value = Jan15TextBox.Value
.Cells(dataRow, 15).Value = Apr15TextBox.Value
.Cells(dataRow, 16).Value = Apr16TextBox.Value
.Cells(dataRow, 17).Value = Apr17TextBox.Value
.Cells(dataRow, 18).Value = Apr18TextBox.Value
.Cells(dataRow, 19).Value = ReasonTextBox.Value
End With
Call UserForm_Initialize
End Sub
Private Sub UserForm_Initialize()
'Fill JobListBox with
With JobListBox
JobListBox.RowSource = "=Overview!A4:A132"
End With
'Empty Apr14TextBox
Apr14TextBox.Value = ""
'Empty Jul14TextBox
Jul14TextBox.Value = ""
'Empty Oct14TextBox
Oct14TextBox.Value = ""
'Empty Jan15TextBox
Jan15TextBox.Value = ""
'Empty Apr15TextBox
Apr15TextBox.Value = ""
'Empty Apr16TextBox
Apr16TextBox.Value = ""
'Empty Apr17TextBox
Apr17TextBox.Value = ""
'Empty Apr18TextBox
Apr18TextBox.Value = ""
'Empty ReasonTextBox
ReasonTextBox.Value = ""
'Start with JobListBox
JobListBox.SetFocus
End Sub
Many thanks
Aramina
I have created a UserForm that adds forecasted staff in post figures to specified columns in a spreadsheet and also allows the user to view and edit any existing figures.
It identifies the correct row to put the data in by looking at the Job Type that has been selected in the JobListBox.
There are 132 rows with one different job type per row on the sheet (no new rows can be added), and the UserForm works perfectly until it gets to Row 112 - any job type on row 112-132 that is selected will have the figures entered randomly in different rows, even though the figures go to the correct place for all the job types on the previous rows.
I can't work out why this is happening - can anyone help? The sheet is sheet 2 (of 2) in the workbook, and is named 'Overview'. My code is below:
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub ClearButton_Click()
Call UserForm_Initialize
End Sub
Private Sub JobListBox_Click()
'Event handler when an entry is selected in the JobListBox, shows existing values
With Sheets(2)
dataRow = WorksheetFunction.Match(JobListBox.Value, .Range("A:A"))
Apr14TextBox.Value = .Cells(dataRow, 5).Value
Jul14TextBox.Value = .Cells(dataRow, 8).Value
Oct14TextBox.Value = .Cells(dataRow, 11).Value
Jan15TextBox.Value = .Cells(dataRow, 14).Value
Apr15TextBox.Value = .Cells(dataRow, 15).Value
Apr16TextBox.Value = .Cells(dataRow, 16).Value
Apr17TextBox.Value = .Cells(dataRow, 17).Value
Apr18TextBox.Value = .Cells(dataRow, 18).Value
ReasonTextBox.Value = .Cells(dataRow, 19).Value
End With
End Sub
Private Sub OKButton_Click()
'Data transfer - instructs Excel on where to put the values entered in text boxes
Dim dataRow As Long
With Sheets(2)
dataRow = WorksheetFunction.Match(JobListBox.Value, .Range("A:A"))
.Cells(dataRow, 5).Value = Apr14TextBox.Value
.Cells(dataRow, 8).Value = Jul14TextBox.Value
.Cells(dataRow, 11).Value = Oct14TextBox.Value
.Cells(dataRow, 14).Value = Jan15TextBox.Value
.Cells(dataRow, 15).Value = Apr15TextBox.Value
.Cells(dataRow, 16).Value = Apr16TextBox.Value
.Cells(dataRow, 17).Value = Apr17TextBox.Value
.Cells(dataRow, 18).Value = Apr18TextBox.Value
.Cells(dataRow, 19).Value = ReasonTextBox.Value
End With
Call UserForm_Initialize
End Sub
Private Sub UserForm_Initialize()
'Fill JobListBox with
With JobListBox
JobListBox.RowSource = "=Overview!A4:A132"
End With
'Empty Apr14TextBox
Apr14TextBox.Value = ""
'Empty Jul14TextBox
Jul14TextBox.Value = ""
'Empty Oct14TextBox
Oct14TextBox.Value = ""
'Empty Jan15TextBox
Jan15TextBox.Value = ""
'Empty Apr15TextBox
Apr15TextBox.Value = ""
'Empty Apr16TextBox
Apr16TextBox.Value = ""
'Empty Apr17TextBox
Apr17TextBox.Value = ""
'Empty Apr18TextBox
Apr18TextBox.Value = ""
'Empty ReasonTextBox
ReasonTextBox.Value = ""
'Start with JobListBox
JobListBox.SetFocus
End Sub
Many thanks
Aramina