Application-defined or object-defined error (1004) in With

michaeltsmith93

Board Regular
Joined
Sep 29, 2016
Messages
83
Hi, in addition to the If statement causing error 13, I'm getting 1004 in the With statement. Thoughts?

Code:
Private Sub OK_Click()
Dim ERow As Long
Dim ws As Worksheet
Set ws = Worksheets("Tracker")


'find first empty row
ERow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    
'check for input
If (Trim(Me.ptmember.Value) Or Trim(Me.StudyRole.Value) Or Trim(Me.MatrixRole.Value) Or Trim(Me.Department.Value)) = "" Then
   MsgBox "Please fill all fields."
   Exit Sub
End If


With ws


[COLOR=#ff0000]    .Cells(ERow, 1).Value = Me.ptmember.Value[/COLOR]
    .Cells(ERow, 2).Value = Me.StudyRole.Value
    .Cells(ERow, 4).Value = Me.MatrixRole.Value
    .Cells(ERow, 5).Value = Me.Department.Value
    
End With


Me.ptmember.Value = ""
Me.StudyRole.Value = ""
Me.MatrixRole.Value = ""
Me.Department.Value = ""


End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
More like
Code:
If Trim(Me.ptmember.Value)="" or Trim(Me.StudyRole.Value)=""...............

The With statement looks good, when it errors out, confirm what the Value of Erow is
 
Upvote 0
Try this to find the next empty row.
Code:
ERow = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
 
Upvote 0
...I'm so upset. I inherited this workbook from someone else. I have no idea why there was something down there.




That fixed it. Thank you, Fluff. You're a Godsend.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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