Hello, I’m after some help. I have made a vba user form which is working ok. I want to add some data validation to it. I have managed to add a little. Example would be Me.textbox1.Value = “” Then
MsgBox "Please enter date", vbCritical
Exit Sub
End If
This works fine for most boxes the issue I have is that not all my textboxes need an entry, some will if others have one. So an example. If Combobox 3 had an entry, then one of Textbox 3 and 4 would need an entry and so would 5. If Combobox 3 had one then Combobox 4, Textbox 6 and 7 would not. If Combobox 4 had an entry then one of Textbox 6 and 7 would need one. If Combobox 4 had one then I would need no entry in Combobox 3 Textbox 3, 4 and 5.
Here is the code I'm using.
Private Sub CommandButton2_Click()
If Me.TextBox1.Value = "" Then
MsgBox "Please enter the date", vbCritical
Exit Sub
End If
If Me.ComboBox1.Value = "" Then
MsgBox "Please enter the team number", vbCritical
Exit Sub
End If
If Me.ComboBox2.Value = "" Then
MsgBox "Please enter the shift", vbCritical
Exit Sub
End If
Dim TargetRow As Integer
TargetRow = Sheets("Engine").Range("C6").Value + 1
Refrence = "Record number " & TargetRow 'End msgbox'
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 0).Value = TargetRow
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 1).Value = TextBox1
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 2).Value = ComboBox1
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 3).Value = "Shop 1"
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 4).Value = ComboBox2
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 5).Value = ComboBox3
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 6).Value = TextBox3
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 7).Value = TextBox4
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 8).Value = TextBox5
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 9).Value = ComboBox4
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 10).Value = TextBox6
Sheets("Input database").Range("Data_Start").Offset(TargetRow, 11).Value = TextBox7
MsgBox "For any dates, did you use number and text? If you have not please edit and do so.", vbInformation
MsgBox Refrence & " was added to the shop 1 Input databse", 0, "Complete"
Unload Add_Record
End Sub
This is well beyond me I hope someone can help
Bookmarks