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
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Fowmy

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

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,298
Messages
5,510,467
Members
408,791
Latest member
bwirth

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top