Run-Time Error '1004'; ?

NYRANGERS423

New Member
Joined
Mar 17, 2016
Messages
27
So I get this when I use my spreadsheet, Rint-Time error '1004'; Application-definded or object-defined error.

Here is the code I have,
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
If Not Intersect(Target, Columns("A")) Is Nothing Then
If Target.Row > 1 And Target.Offset(, 2) = "" Then
Target.Offset(, 2) = Date
Target.Offset(, 6) = Time
**Target.Offset(, 8) = Worksheets("Name List").Range("E2").Value
End If
ElseIf Not Intersect(Target, Columns("B")) Is Nothing Then
If Target.Row > 1 And Target.Offset(, 6) = "" And Target.Offset(, 1) <> " " Then
Target.Offset(, 6) = Time
Target.Offset(, 9) = Worksheets("Name List").Range("E2").Value
End If
End If
End If
End Sub

**The Star indicates where the error occurs.
What I don't get is I have the same line of code a little farther down "Target.Offset(, 9) = Worksheets("Name List").Range("E2").Value" and it works just fine. Is excel not able to find the cell?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
When using the Worksheet_Change event procedure, if you are updating cell values within it, it is best to disable events while those updates happen so the event procedure doesn't call itself and get caught in an endless loop.

Also, VBA will only show you the first error it encounters (so there may be others that you many not see until you fix the first one).

So give those code a try (and use Code tags when posting your code, especially when nesting IF statements -- it makes it much easier to read!;))
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Count = 1 Then
        If Not Intersect(Target, Columns("A")) Is Nothing Then
            If Target.Row > 1 And Target.Offset(, 2) = "" Then
                Application.EnableEvents = False
                Target.Offset(, 2) = Date
                Target.Offset(, 6) = Time
                Target.Offset(, 8) = Worksheets("Name List").Range("E2").Value
                Application.EnableEvents = True
            End If
        ElseIf Not Intersect(Target, Columns("B")) Is Nothing Then
            If Target.Row > 1 And Target.Offset(, 6) = "" And Target.Offset(, 1) <> " " Then
                Application.EnableEvents = False
                Target.Offset(, 6) = Time
                Target.Offset(, 9) = Worksheets("Name List").Range("E2").Value
                Application.EnableEvents = True
            End If
        End If
    End If
    
End Sub
 
Upvote 0
When using the Worksheet_Change event procedure, if you are updating cell values within it, it is best to disable events while those updates happen so the event procedure doesn't call itself and get caught in an endless loop.

Also, VBA will only show you the first error it encounters (so there may be others that you many not see until you fix the first one).

So give those code a try (and use Code tags when posting your code, especially when nesting IF statements -- it makes it much easier to read!;))
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Count = 1 Then
        If Not Intersect(Target, Columns("A")) Is Nothing Then
            If Target.Row > 1 And Target.Offset(, 2) = "" Then
                Application.EnableEvents = False
                Target.Offset(, 2) = Date
                Target.Offset(, 6) = Time
                Target.Offset(, 8) = Worksheets("Name List").Range("E2").Value
                Application.EnableEvents = True
            End If
        ElseIf Not Intersect(Target, Columns("B")) Is Nothing Then
            If Target.Row > 1 And Target.Offset(, 6) = "" And Target.Offset(, 1) <> " " Then
                Application.EnableEvents = False
                Target.Offset(, 6) = Time
                Target.Offset(, 9) = Worksheets("Name List").Range("E2").Value
                Application.EnableEvents = True
            End If
        End If
    End If
    
End Sub

Ok I tried the code and It did and didn't work. Another error occurred but It said the cell I was writing to was protected. HAHA I forgot to unchecked the locked in protection table for that column. After I did that both your and my old code worked. I am going to use your cause it looks cleaner. HAHA thanks sooo much. I appreciate it. :LOL:
 
Upvote 0
You're welcome.

I guess I will be rooting for your Rangers in the playoffs this year, as my Sabres won't be in playoffs yet again this year! Maybe next year...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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