+ Reply to Thread
Results 1 to 8 of 8

Macros do not work on a PC but do on other ones

  1. #1
    Registered User
    Join Date
    05-15-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2016
    Posts
    8

    Macros do not work on a PC but do on other ones

    Hi all,

    Here is the code with 6 alternatives to execute a simple ".Sort.SortFields.Clear" command.

    None of them work on my PC but they all do on other computers. All alternatives on my PC show the

    "run-time error '9': subscript out of range". Please note that I get the same error with the "AutoFilter" command.

    This thread has also been posted on the Microsoft community website.

    Thanks very much, Alan.

    Sub test_autosort()
    ActiveWorkbook.Worksheets("Sheet1").AutoFilterMode = False
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual


    ' 1st alternative
    ' Rows("6:800").Select
    ' Worksheets("Sheet1").Sort.SortFields.Clear

    ' 2nd alternative
    ' With ActiveSheet
    ' .Sort.SortFields.Clear
    ' End With

    ' 3rd alternative
    ' With Worksheets("Sheet1")
    ' .Sort.SortFields.Clear
    ' End With

    ' 4th alternative
    ' With Worksheets(1)
    ' .Sort.SortFields.Clear
    ' End With
    '
    '5th alternative
    'ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear


    '6th alternative
    With ActiveWorkbook
    Worksheets(1).Sort.SortFields.Clear
    End With

    End Sub

    .Sort.Sortfields.Clear.PNG

  2. #2
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Perth Western Australia
    MS-Off Ver
    Office 365
    Posts
    257

    Re: Macros do not work on a PC but do on other ones

    Hi
    Could you please upload a sample of your excel file so I can test on my computer as it will make it easier to solve your issue.

    Cheers

  3. #3
    Registered User
    Join Date
    05-15-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2016
    Posts
    8

    Re: Macros do not work on a PC but do on other ones

    Voilą!

    Thanks!
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Perth Western Australia
    MS-Off Ver
    Office 365
    Posts
    257

    Re: Macros do not work on a PC but do on other ones

    Hi
    I do not get a runtime error however the

    Please Login or Register  to view this content.

    does not actually do anything.
    What were you trying to achieve?

    Cheers

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Macros do not work on a PC but do on other ones

    I don't get any errors on any of the alternatives. But, as there's no data, it's difficult to determine what might be the problem.

    What's different about your PC? Compared to the others, that is.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Registered User
    Join Date
    05-15-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2016
    Posts
    8

    Re: Macros do not work on a PC but do on other ones

    Well, I have some files with numerous macros and with some large data set and I want to apply a sort to a range with several columns. So what I want to achieve is to first clear any previous sort
    that was applied via previous macros and then proceed with a new sort. Please note that I have the same problem with the "AutoFilter.Sort.SortFields.Clear" command. I have created and attached a
    new file with some data and new alternative macros to clear the autofilter. I get the same problem.

    Thanks again!
    Attached Files Attached Files

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Macros do not work on a PC but do on other ones

    If this:

    Please Login or Register  to view this content.
    gives you a runtime error 9, it's because of some other event code that you have. If you start Excel in safe mode (hold down the Ctrl key while starting the application) and then open that workbook and run the code, do you still get the error?
    Rory

  8. #8
    Registered User
    Join Date
    05-15-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2016
    Posts
    8

    Re: Macros do not work on a PC but do on other ones

    Hi rorya,

    I started Excel in safe mode and then ran the macro several times. Everytime Excel tries to start the macro (all alternatives) and then shuts down. Then it tries to reopen the file.

    Thanks.

    Alan

+ 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. Sending File with Macros - Macros do not work
    By milwaukee in forum Excel General
    Replies: 1
    Last Post: 09-15-2015, 08:21 PM
  2. Macros do not work on another PC
    By Dimy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-25-2015, 03:26 AM
  3. Combine Two Macros so they Work Together
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2015, 12:42 PM
  4. [SOLVED] Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-27-2013, 11:55 AM
  5. Macros stop to work when work sheet is protected. Run time error 1004
    By sellim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2012, 01:14 AM
  6. Why do Macros work sometimes?
    By ctmurray in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-13-2008, 05:08 PM
  7. macros don't work
    By alymcmorland in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2005, 08:05 AM

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