Jin Asterich
Jin Asterich

Reputation: 63

Error 1004 "Application-defined or Object-defined error

I have a Userform with Textboxes in it.

When I try to click the Submit button in the form, I get an error Error 1004 "Application-defined or Object-defined error". Why am I getting that error?

Here's the code

Private Sub btnSubmit_Click()
    Sheet2.Activate
    Dim lastRow2 As Long
    lastRow2 = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row + 1

    Sheets("Sheet2").Range("A" & lr4).Value = CDate(Me.tbDate).Value
    Sheets("Sheet2").Range("B" & lr4).Value = Me.tbProduct.Value
    Sheets("Sheet2").Range("C" & lr4).Value = Me.tbQty.Value
    Sheets("Sheet2").Range("D" & lr4).Value = Me.tbPrice.Value        
End Sub

Private Sub UserForm_Initialize()
    Me.tbDate.Value = Date
    Me.tbProduct.Value = ""
    Me.tbQty.Value = ""
    Me.tbPrice.Value = ""
End Sub

Upvotes: 1

Views: 76

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149305

You are getting that error because lr4 is 0.

Sheets("Sheet2").Range("A" & lr4).Value = CDate(Me.tbDate).Value

More Clarification

Once you fix the value of lr4, you will not get the Applicaiton Defined Error as mentioned in your question. You will however get a syntax error becuase of .Value in Cdate. Remove that or change it to CDate(Me.tbDate.Value)

Upvotes: 1

Related Questions