PHIL.Pearce84
Board Regular
- Joined
- May 16, 2011
- Messages
- 152
- Office Version
- 365
- Platform
- Windows
Evening,
I've been creating a VBA form to add data to a sheet, it was working until I added in the OptionButton part to populate "Provided" and"Reconciled" in column F and now I get a compile error that says:
"Block if without End If"
But I cant work it out, can anyone help please?
Private Sub CommandButton1_Click()
'''''''''' Validation ''''''''''
If Me.TextBox1.Value = "" Then
MsgBox "Please Enter a Valid Forename"
Exit Sub
End If
If Me.TextBox2.Value = "" Then
MsgBox "Please Enter a Valid Surname"
Exit Sub
End If
If Me.TextBox3.Value = "" Then
MsgBox "Please Enter a Address"
Exit Sub
End If
If VBA.IsNumeric(Me.TextBox4.Value) = False Then
MsgBox "Please Enter a Valid Amount"
Exit Sub
If Me.OptionButton1.Value = False And Me.OptionButton2.Value = False Then
MsgBox "Please valid status"
Exit Sub
End If
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("sheet3")
Dim n As Long
n = sh.Range("A" & Application.Rows.Count).End(xlUp).Row
sh.Unprotect "1234"
sh.Range("A" & n + 1).Value = Me.TextBox1.Value
sh.Range("B" & n + 1).Value = Me.TextBox2.Value
sh.Range("C" & n + 1).Value = Me.TextBox3.Value
sh.Range("D" & n + 1).Value = Me.TextBox4.Value
If Me.OptionButton1.Value = True Then sh.Range("E" & n + 1).Value = "Provided"
If Me.OptionButton2.Value = True Then sh.Range("E" & n + 1).Value = "Reconciled"
sh.Protect "1234"
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.OptionButton1.Value = False
Me.OptionButton2.Value = False
MsgBox "New Record Has Been Added", vbInformation
End Sub
I've been creating a VBA form to add data to a sheet, it was working until I added in the OptionButton part to populate "Provided" and"Reconciled" in column F and now I get a compile error that says:
"Block if without End If"
But I cant work it out, can anyone help please?
Private Sub CommandButton1_Click()
'''''''''' Validation ''''''''''
If Me.TextBox1.Value = "" Then
MsgBox "Please Enter a Valid Forename"
Exit Sub
End If
If Me.TextBox2.Value = "" Then
MsgBox "Please Enter a Valid Surname"
Exit Sub
End If
If Me.TextBox3.Value = "" Then
MsgBox "Please Enter a Address"
Exit Sub
End If
If VBA.IsNumeric(Me.TextBox4.Value) = False Then
MsgBox "Please Enter a Valid Amount"
Exit Sub
If Me.OptionButton1.Value = False And Me.OptionButton2.Value = False Then
MsgBox "Please valid status"
Exit Sub
End If
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("sheet3")
Dim n As Long
n = sh.Range("A" & Application.Rows.Count).End(xlUp).Row
sh.Unprotect "1234"
sh.Range("A" & n + 1).Value = Me.TextBox1.Value
sh.Range("B" & n + 1).Value = Me.TextBox2.Value
sh.Range("C" & n + 1).Value = Me.TextBox3.Value
sh.Range("D" & n + 1).Value = Me.TextBox4.Value
If Me.OptionButton1.Value = True Then sh.Range("E" & n + 1).Value = "Provided"
If Me.OptionButton2.Value = True Then sh.Range("E" & n + 1).Value = "Reconciled"
sh.Protect "1234"
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.OptionButton1.Value = False
Me.OptionButton2.Value = False
MsgBox "New Record Has Been Added", vbInformation
End Sub