Results 1 to 25 of 25

Error 1004 - object-defined error when vba code not applicable

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-21-2011
    Location
    Australia, Perth
    MS-Off Ver
    Excel 2010
    Posts
    159

    Error 1004 - object-defined error when vba code not applicable

    Hi folks,

    Through playing around with the macro recorder and looking at other macros, I have written the following:

    Sub Fill_Gaps_Spreadsheet()
    
    ' Interrupts Automatic Calculation, ScreenUpdating and StatusBar
    
    Application.Calculation = xlCalculationManual
    
    Application.ScreenUpdating = False
    
    Application.DisplayStatusBar = False
    
    ' Converts column D to number
    
        Range("d2:D70000").Select
        With Selection
            Selection.NumberFormat = "General"
            .Value = .Value
        End With
    
    ' Replaces current blank unit price with start of year unit price
    
        Range("Q2:Q70000").Select
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.FormulaR1C1 = "=RC[31]"
    
    
    ' Calculates Min Stock Value & SOH Value for current range
    
        Columns("R:R").Select
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.FormulaR1C1 = "=RC[-1]*RC[-10]"
    
        Range("T:T").Select
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.FormulaR1C1 = "=RC[-3]*RC[-9]"
    
    ' Imports old stock
    
        Range("AM2:AM70000").Select
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.FormulaR1C1 = "=INDEX(OldMinMax!R2C4:R129556C4,MATCH(RC[-38]&RC[-35],OldMinMax!R2C1:R129556C1,0))"
    
    ' Import current min where old stock is not available
    
        Columns("AM2:AM70000").Select
        Selection.SpecialCells(xlCellTypeFormulas, 16).Select
        Selection.FormulaR1C1 = "=RC[-31]"
    
    ' Imports current min where SOH is Nil
    
        Range("h2:h70000").Select
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.FormulaR1C1 = "=INDEX(CurrentMinMax!R2C4:R100000C4,MATCH(RC[-7]&RC[-4],CurrentMinMax!R2C1:R100000C1,0))"
    
    
    ' Removes index&match formula on old & current min
    
    Dim smallrng As Range
    
        For Each smallrng In Range("AM2:AM70000,H2:H70000,Q2:Q70000,R2:R70000,T2:T70000").Areas
    
            With smallrng
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select
            End With
            Application.CutCopyMode = False
    
    Next smallrng
    
    
    ' Restores Automatic Calculation, ScreenUpdating and StatusBar
    
    Application.Calculation = xlCalculationAutomatic
    
    Application.ScreenUpdating = True
    
    Application.DisplayStatusBar = True
    
    End Sub
    My only issue is that if one of the elements of the macro does not apply (eg there are no blank cells in R:R), I have an error and the macro does not run.

    Can someone please tell me what to add to bypass this problem and allow the macro to continue running? Also, if any of you can see a way to speed up the processing of the macro (which takes quite a bit of time at the moment), I'll be very grateful :-)

    Thanks in advance.
    S
    Last edited by SubwAy; 06-08-2016 at 08:51 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Error message: Run-Time error '1004 '; application-defined or object-defined error
    By Davasu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2015, 06:52 AM
  2. Replies: 1
    Last Post: 10-22-2015, 05:50 AM
  3. Replies: 5
    Last Post: 08-19-2015, 07:10 PM
  4. HELP WITH ERROR CODE '1004' Application-defined or object defined error
    By QuintonMcCloud in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-20-2015, 03:34 PM
  5. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  6. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  7. Replies: 2
    Last Post: 09-12-2012, 01:01 PM

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