+ Reply to Thread
Results 1 to 7 of 7

Need Macro to run no matter what a worksheet is name

  1. #1
    Registered User
    Join Date
    04-11-2014
    Location
    Greensboro, NC
    MS-Off Ver
    Excel 2007
    Posts
    10

    Need Macro to run no matter what a worksheet is name

    Hello,

    Have several users running this report. Depending on the user the first worksheet may have a different name - ex. FGlistmonthly or Design_Responsibility_name, etc. Second Worksheet may be Sheet1 or Sheet5, etc. Need Macro to run no matter what the Worksheets are name without having to change Macro if possible. Usually is what I do to match the Worksheet name. Thanks for any help.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by alansidman; 05-24-2017 at 09:53 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: Need Macro to run no matter what a worksheet is name

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    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, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Need Macro to run no matter what a worksheet is name

    The answer is in your code.
    Use the With and End With statement
    Please Login or Register  to view this content.
    Make sure to use the . (period) as required.

    BTW, read up on selecting. In your code it is not needed at all. It slows down the code.

    Oh, instead of all the changing of the column widths, would this not work at the end?
    Please Login or Register  to view this content.
    Is there a good reason why some columns are deleted and shifted right, others left and other cut?
    The deleting and inserting columns is a mixed bag also. Not a good way of doing it. I realize it was a recorded macro but you should clean it up.
    Maybe if you explain what you want done, someone will come up with a neater and certainly faster and better piece of code.
    Last edited by jolivanes; 05-25-2017 at 12:08 AM.

  4. #4
    Registered User
    Join Date
    04-11-2014
    Location
    Greensboro, NC
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Need Macro to run no matter what a worksheet is name

    Sorry about not posting code between
    Please Login or Register  to view this content.
    tags. Thanks for your help!

  5. #5
    Registered User
    Join Date
    04-11-2014
    Location
    Greensboro, NC
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Need Macro to run no matter what a worksheet is name

    Hi Jolivanes,

    Trying to do this on my own but unfortunately I don't have much time and the end of the month is coming fast.
    Thanks for all your help!
    In my brief tutorial studies I had not come across the Autofit line. Mostly been creating programs that say "Hello". But that line worked!
    I will definitely read up on selecting and see how much more I can clean this up.

    Thanks again!
    roxie

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need Macro to run no matter what a worksheet is name

    You can also place this at the beginning of your code

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-11-2014
    Location
    Greensboro, NC
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Need Macro to run no matter what a worksheet is name

    Hi John,

    I'll try this also.

    Thanks for your help!

+ 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. One tab just won't print no matter what!
    By Brumbot in forum Excel General
    Replies: 2
    Last Post: 11-29-2016, 07:27 PM
  2. Mail macro that works no matter what OS?
    By horsefish01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-26-2015, 06:51 PM
  3. Macro (probably?) to auto-number a column, no matter where a row is inserted
    By dtrimble in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2015, 08:37 PM
  4. Indirect.ext keep getting #REF no matter what!
    By natasha89 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-07-2012, 01:30 AM
  5. [SOLVED] Wrong worksheet opens when I open the file, no matter how I leave it when I close
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2012, 03:53 PM
  6. [SOLVED] Macro for filter on protected workbook that works for all sheets, no matter what sheets are named?
    By StargateFanFromWork in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-26-2006, 02:35 PM
  7. A Complicated Matter...
    By SamuelT in forum Excel General
    Replies: 4
    Last Post: 01-24-2006, 09:52 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