Results 1 to 7 of 7

Runtime error 1004 - Application Defined or Object Defined error

Threaded View

  1. #1
    Registered User
    Join Date
    06-06-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010 and Excel 2013
    Posts
    21

    Angry Runtime error 1004 - Application Defined or Object Defined error

    I have a macro, that worked before I put in a For...Next Statement. Now I get an error which did not happen before the changes. The error reads: Runtime error 1004 - Application Defined or Object Defined error.

    The line on which I get the error is as follows: ActiveSheet.Range("J" & ROW_NO).Select and I cannot figure out why. The ROW_NO is defined as Dim ROW_NO As Long and is initialised as follows:ROW_NO = 2

    For the sake of completeness, I supply the entire code below:



    Sub Macro1()
    '
    ' Macro1 Macro
    '
    ' ============================
    ' Define Variables & Populate them
    ' ============================
       Dim fname As String
       Dim FIL_NAM1 As Long
       Dim ROW_NO As Long
       Dim INVCNT As Long
       Dim COUNTER As Long
       Dim ws1 As Worksheet
       FIL_NAM1 = 2
       ROW_NO = 7
       COUNTER = 1
       
    ' ==================================================
    ' Copy First Invoice Detail to Invoice Control Sheet
    ' ==================================================
            Workbooks.Open Filename:= _
            "C:\Users\E-Machine\Dropbox\Technology Station - VUT\Master Invoice TS.xlsm"
            Sheets("Invoices").Select
            Range("D" & FIL_NAM1).Select
            
            INVCNT = Range("C2").Value
        For COUNTER = 1 To INVCNT
            DoWork
        Next COUNTER
            
            
    
    End Sub
    Sub DoWork()
            fname = "C:\Users\E-Machine\Dropbox\Technology Station - VUT\Invoices\" & ActiveCell.Value
            Workbooks.Open fname
            Cells.Select
            Selection.Copy
            ActiveWindow.Close
            Windows("Invoice Control Sheet.xlsm").Activate
            Sheets.Add After:=ActiveSheet
            ActiveSheet.Paste
            ActiveSheet.Range("I1:J1").Select
            Selection.Copy
            Sheets("Sheet1").Select
            ActiveSheet.Range("J" & ROW_NO).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
               :=False, Transpose:=False
            Sheets("Sheet2").Select
            Range("I2:J2").Select
            Application.CutCopyMode = False
            Selection.Copy
            Application.WindowState = xlMinimized
            Windows("Master Invoice TS.xlsm").Activate
            Application.WindowState = xlNormal
            Windows("Invoice Control Sheet.xlsm").Activate
            Sheets("Sheet1").Select
            Range("B" & ROW_NO).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Sheets("Sheet2").Select
            Range("I3:J3").Select
            Application.CutCopyMode = False
            Selection.Copy
            Sheets("Sheet1").Select
            Range("C" & ROW_NO).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
               :=False, Transpose:=False
            Sheets("Sheet2").Select
            Range("B5:D5").Select
            Application.CutCopyMode = False
            Selection.Copy
            Sheets("Sheet1").Select
            Range("D" & ROW_NO).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Sheets("Sheet2").Select
            Range("I4:J4").Select
            Application.CutCopyMode = False
            Selection.Copy
            Sheets("Sheet1").Select
            Range("G" & ROW_NO).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
               :=False, Transpose:=False
            Sheets("Sheet2").Select
            Range("I21:J21").Select
            Application.CutCopyMode = False
            Selection.Copy
            Sheets("Sheet1").Select
            Range("K" & ROW_NO).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                 :=False, Transpose:=False
            Range("K" & ROW_NO).Select
            Application.CutCopyMode = False
            Selection.Style = "Comma"
            Sheets("Sheet2").Select
            ActiveWindow.SelectedSheets.Delete
            Windows("Invoice Control Sheet.xlsm").Activate
            Application.WindowState = xlNormal
            FIL_NAM1 = FIL_NAM1 + 1
            ROW_NO = ROW_NO + 1
        
            Sheets("Sheet1").Select
    End Sub
    Last edited by andreroux; 06-06-2013 at 10:32 AM. Reason: Use tags to use less page space

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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