Block if without end if compile error

jcaptchaos2

Well-known Member
Joined
Sep 24, 2002
Messages
1,026
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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Fowmy

Well-known Member
Joined
Jul 10, 2008
Messages
512
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,133,325
Messages
5,658,165
Members
418,430
Latest member
Chlwls808

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
Top