+ Reply to Thread
Results 1 to 8 of 8

Subtotal Macro Run Time error 1004 range of object global failed

  1. #1
    Registered User
    Join Date
    04-09-2014
    Location
    Grand Prairie, TX
    MS-Off Ver
    Excel 2010
    Posts
    7

    Subtotal Macro Run Time error 1004 range of object global failed

    I am very new to macros. I recorded a macro on a spreadsheet and tried to generalize it to accommodate various number of rows in the data. I am now getting a Run Time error of 1004 that says
    Method of 'Range' of object' _global' failed.

    The line of code that is in yellow is:
    ActiveSheet.Sort.SortFields.Add Key:=Range("Won or Lost Quote"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal


    The full code I have is:

    Cells.Select
    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=Range("Won or Lost Quote"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    ActiveSheet.Sort.SortFields.Add Key:=Range("Quote Requested By"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.ActiveSheet.Sort
    .SetRange Range("myData")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Cells.Select
    Selection.Subtotal GroupBy:=13, Function:=xlSum, TotalList:=Array(16), _
    Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Subtotal Macro Run Time error 1004 range of object global failed

    Is the "Won or Lost Quote" named range on the ActiveSheet when the Macro runs?

  3. #3
    Registered User
    Join Date
    04-09-2014
    Location
    Grand Prairie, TX
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Subtotal Macro Run Time error 1004 range of object global failed

    Yes, it is column M then I am sorting by column H which is Quote Requested By. There can be varying number of lines in the spreadsheet from month to month.

  4. #4
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Subtotal Macro Run Time error 1004 range of object global failed

    Hi,

    Here is a macro that will do what you need.
    I hope I got the range referencing correct
    Just change it as needed. It assumes your list starts at cell A1. If it does not, just change A1 to the first (top left) cell in your data block.

    BTW: The CurrentRegion property is perfect for dynamically picking up the size (dimension) of your list. (Great to use in macros )

    Please Login or Register  to view this content.
    Regards,
    Rudi

  5. #5
    Registered User
    Join Date
    04-09-2014
    Location
    Grand Prairie, TX
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Subtotal Macro Run Time error 1004 range of object global failed

    Thank you so much for the reply. I am still getting a run time error and the line highlighted in yellow is the second Range line:
    .Range("A1").CurrentRegion.Subtotal GroupBy:=13, Function:=xlSum, TotalList:=Array(16), _
    Replace:=True, PageBreaks:=False, SummaryBelowData:=True

  6. #6
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Subtotal Macro Run Time error 1004 range of object global failed

    The syntax of that line is all correct. The only reason for the error is due to one of the arguments not complying to the list you are working on.
    Check if your list complies with the RED arguments below.

    GroupBy:=13, --- This is referencing the 13th column in your list. Since we are sorting on column 'M', this is 13 columns.
    Function:=xlSum, --- This is subtotaling with the sum expression. Does column 16 contain values to sum??
    TotalList:=Array(16), _ --- This is a reference to column 16 in your list (column 'P'). Is there a column P? Does it contain numerical values?

    Replace:=True, --- This replaces current subtotals (This is not the error source!)
    PageBreaks:=False, --- This inserts page breaks (This is not the error source!)
    SummaryBelowData:=True --- This is the subtotals position (This is not the error source!)

  7. #7
    Registered User
    Join Date
    04-09-2014
    Location
    Grand Prairie, TX
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Subtotal Macro Run Time error 1004 range of object global failed

    Thank you so much. I trashed the file I was working in and made a new file and copied this in and it worked. Don't understand at all what happened because data was the same data just in different workbook. It works perfectly now. Thank you so much! need to mark this thread resolved! YAY!

  8. #8
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Subtotal Macro Run Time error 1004 range of object global failed

    Excellent.
    Thanks for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. runtime error 1004 range of object global failed excel 2010
    By kwesmc1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2014, 05:22 PM
  2. [SOLVED] run time error 1004 range of object _worksheet failed
    By goss in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-16-2013, 08:49 AM
  3. Run-time error '1004': Method 'Range' of object 'Global' failed
    By djwestholm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2012, 04:52 PM
  4. Run-time error '1004': Method 'Range' of object '_ Global' failed
    By mdvc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-20-2011, 11:48 AM
  5. runtime error 1004 method range of object global failed
    By dreamz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2006, 03:25 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