Results 1 to 6 of 6

Excel 2007 : Why am I getting this 1004 error?

Threaded View

  1. #1
    Registered User
    Join Date
    12-05-2011
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2007
    Posts
    40

    Question Why am I getting this 1004 error?

    Hello folks,

    Below is a block of code that is attempting to first find the last Row number of some imported data on a spreadsheet (A), then take a value entered by the user (on a different sheet B) and paste it into another column of the original spreadsheet (A). only pasting the same number of rows as was determined to be in the imported data.

    The determination of the last Row number (LastRow) seems to work fine.

    The pasting part of the code works just fine if I hard coded a value for the last Row number (like use 6725 instead of "LastRow").

    But when I try to use my "LastRow" variable in the pasting code, I get an error:

    "Run-time error '1004':
    Application-defined or object-defined error"

    And clicking the Debug button highlights the line (in yellow):

    .Range(.Range("L4"), .Range("L" & "LastRow")).Value = Target.Value

    Any idea why I am getting this error here?

    Sub Worksheet_Change(ByVal Target As Range)
    
        With Sheets("AIO-Cond").Range("A1")
            With .Cells(.Rows.Count, Range("A1").Column)
                If Not IsEmpty(.Value) Then
                    LastRow = .Row
                ElseIf IsEmpty(.End(xlUp)) Then
                    LastRow = ""
                Else
                    LastRow = .End(xlUp).Row
                End If
             End With
        End With
        
        If Target.Address = "$D$4" Then
        With Sheets("AIO-Cond")
        .Range(.Range("L4"), .Range("L" & "LastRow")).Value = Target.Value
        End With
        End If
    
        If Target.Address = "$D$5" Then
        With Sheets("AIO-Cond")
        .Range(.Range("M4"), .Range("M" & "LastRow")).Value = Target.Value
        End With
        End If
    
        If Target.Address = "$D$6" Then
        With Sheets("AIO-Cond")
        .Range(.Range("N4"), .Range("N" & "LastRow")).Value = Target.Value
        End With
        End If
    
    End Sub
    Last edited by ThomasHaller; 12-15-2011 at 09:41 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1