Block if without end if compile error

jcaptchaos2

Well-known Member
Joined
Sep 24, 2002
Messages
1,032
Office Version
  1. 365
Platform
  1. Windows
I am not sure what I did to this code but now I am getting an error "Block If without end if" Could someone take a look to see if it's something obvious.

Thanks

Code:
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
  .End(xlUp).Offset(1, 0).Row

'check for a Employee number
If Trim(Me.txtempl.Value) = "" Then
  Me.txtempl.SetFocus
  MsgBox "Please enter a Employee Number"
  Exit Sub
End If

'check for a Item number
If Trim(Me.txtitemno.Value) = "" Then
  Me.txtitemno.SetFocus
  MsgBox "Please enter a Item Number"
  Exit Sub
End If

'check for a Shop Order number
If Trim(Me.txtshop.Value) = "" Then
  Me.txtshop.SetFocus
  MsgBox "Please enter a Shop Order Number"
  Exit Sub
End If

'check for a Operation number
If Trim(Me.txtopno.Value) = "" Then
  Me.txtopno.SetFocus
  MsgBox "Please enter a Operation Number"
  Exit Sub
  
  
'copy the data to the database
With ws
  .Cells(iRow, 1).Value = Me.txtempl.Value
  .Cells(iRow, 2).Value = Me.txtitemno.Value
  .Cells(iRow, 3).Value = Me.txtshop.Value
  .Cells(iRow, 4).Value = Me.txtopno.Value
  .Cells(iRow, 5).Value = Me.txtgood.Value
  .Cells(iRow, 6).Value = Me.txtscrapqty.Value
  .Cells(iRow, 7).Value = Me.txtscrapcode.Value
  .Cells(iRow, 8).Value = Me.txtstart.Value
  .Cells(iRow, 9).Value = Time
  .Cells(iRow, 10).Value = Date
End With

'clear the data
Me.txtempl.Value = ""
Me.txtitemno.Value = ""
Me.txtshop.Value = ""
Me.txtopno.Value = ""
Me.txtgood.Value = ""
Me.txtscrapqty.Value = ""
Me.txtscrapcode.Value = ""
Me.txtstart.Value = ""
Me.txtempl.SetFocus

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Check this portion of the code, an end if is missing I suppose.

Rich (BB code):
If Trim(Me.txtopno.Value) = "" Then
  Me.txtopno.SetFocus
  MsgBox "Please enter a Operation Number"
  Exit Sub
 end if
 
Upvote 0

Forum statistics

Threads
1,214,403
Messages
6,119,308
Members
448,886
Latest member
GBCTeacher

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top