+ Reply to Thread
Results 1 to 6 of 6

Issue with recorded macro in Excel

  1. #1
    Registered User
    Join Date
    01-10-2015
    Location
    Dublin, Ireland
    MS-Off Ver
    Office 2013
    Posts
    29

    Issue with recorded macro in Excel

    Hi, I have macros which are stored in Personal.xlsb

    I recently created a new one using "Record Macro".

    When I run the macro it errors. The reason is that in several steps, it refers to a filename specifically (and the file being used is a different name)

    How do I change the code so that it will work with any file?

    Tommy

    Please Login or Register  to view this content.
    ActiveWorkbook.Worksheets("Transaction_Export_16.11.2021_0").Sort.SortFields. _
    Clear
    ActiveWorkbook.Worksheets("Transaction_Export_16.11.2021_0").Sort.SortFields. _
    Add2 Key:=Range("D2:D1001"), SortOn:=xlSortOnValues, Order:=xlAscending, _
    DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Transaction_Export_16.11.2021_0").Sort
    Please Login or Register  to view this content.
    [/CODE]
    Last edited by butterscotch; 11-17-2021 at 12:08 PM.

  2. #2
    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: Issue with recorded macro in Excel

    That code doesn't include a file name but does include a sheet name. If you want it to work on whatever sheet is active currently, just replace ActiveWorkbook.Worksheets("Transaction_Export_16.11.2021_0") with Activesheet
    Rory

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Issue with recorded macro in Excel

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    01-10-2015
    Location
    Dublin, Ireland
    MS-Off Ver
    Office 2013
    Posts
    29

    Re: Issue with recorded macro in Excel

    Thanks for the response. That worked, but highlighted another issue.

    I attach the entire code.

    It is a file that I download from my bank and then format (among others) the "Paid Out" column to a negative value.

    When I run the macro, it does all the other steps, but the values are not negative.

    Any Ideas
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-10-2015
    Location
    Dublin, Ireland
    MS-Off Ver
    Office 2013
    Posts
    29

    Re: Issue with recorded macro in Excel

    Apologies and done

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Issue with recorded macro in Excel

    Quote Originally Posted by butterscotch View Post
    Apologies and done
    Sorry, but it's not done. Please edit post #1.

    There are two ways to add code tags. One is to select the code part of the text so it is highlighted, then press the "#" button in the edit controls. The other is to simply type in the tags:

    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]


    Why use code tags? Code tags:

    1. Are required by rules (see rule #2)
    2. Preserve spacing used to show code structure (otherwise leading spaces and repeated spaces are removed)
    3. Add scroll bars to navigate code with long lines or a lot of lines

+ 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. Macro recorded with errors in Excel VBA
    By gtg430i in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-11-2020, 05:39 PM
  2. [SOLVED] Issue regarding recorded Macro to transfer data from Input sheet to Storage sheet
    By Hirad001 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-29-2015, 04:26 PM
  3. [SOLVED] Need to take off Recorded Macro which minimizes the Excel program
    By cesarmontoya in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2013, 02:30 PM
  4. [SOLVED] Recorded Pivot Table Macro Doesn't Do What I Recorded!
    By diakonos1984 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2013, 11:01 AM
  5. [SOLVED] excel 2007 chart macro graphs data only from sheet on which macro was recorded
    By JW1028 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-19-2013, 06:33 PM
  6. Adding vlookup value in excel recorded macro
    By peednaswan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-17-2012, 03:57 AM
  7. Excel VBA error-recorded a macro to sort
    By Leena in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-13-2005, 11:06 AM

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