+ Reply to Thread
Results 1 to 8 of 8

One Macros for Many Sheets

  1. #1
    Forum Contributor
    Join Date
    02-23-2015
    Location
    SG
    MS-Off Ver
    MS Excel 2019 & 365
    Posts
    241

    One Macros for Many Sheets

    I have two buttons in both sAAA and skAAA sheets that execute 2 different macros (search and check)
    I am trying to keep these macros in the module with only 1 each so that whenever I added more sheets, e.g. sBBB and skBBB, sCCC and skCCC and so on, I do not need to duplicate the 2 macros for all sheets.

    How can I make the code automatic to select the sheet which I am viewing and execute the macros?
    I have attached the sample file for reference. Thanks.
    Below one of the code from the sample file.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by cyliyu; 10-22-2020 at 11:55 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: One Macros for Many Sheets

    The sheet you are viewing is the activesheet.

  3. #3
    Forum Contributor
    Join Date
    02-23-2015
    Location
    SG
    MS-Off Ver
    MS Excel 2019 & 365
    Posts
    241

    Re: One Macros for Many Sheets

    Thanks. Will check and give it a try.

  4. #4
    Forum Contributor
    Join Date
    02-23-2015
    Location
    SG
    MS-Off Ver
    MS Excel 2019 & 365
    Posts
    241

    Re: One Macros for Many Sheets

    Hello,
    I managed solve the code.
    But, I need some advise to improve my IF statement.
    The sample came with only 4 sheets (AAA & BBB 2 each).
    If more sheets to be addon, how can I improve the code? Thanks.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: One Macros for Many Sheets

    Here is an approach.


    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-23-2015
    Location
    SG
    MS-Off Ver
    MS Excel 2019 & 365
    Posts
    241

    Re: One Macros for Many Sheets

    Thanks, Maniacb.

    The statement restricted to 3 char.
    If a sheet name is more then 3, it will not work.
    Is it possble to have it flexible too?

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: One Macros for Many Sheets

    I thought that might be a problem, but don't know relationship between skBBB and BBB. Try this

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    02-23-2015
    Location
    SG
    MS-Off Ver
    MS Excel 2019 & 365
    Posts
    241

    Re: One Macros for Many Sheets

    Thanks for the guidance & hints.

    I make changes to the code.
    The workbook stored many products and AAA repersent product A where c (cXXX) refer to a chart and s (sXXX) for serach etc.

    Please Login or Register  to view this content.
    Last edited by cyliyu; 10-22-2020 at 11:59 PM.

+ 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. Getting Macros to run on protected sheets
    By UWBadger in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-07-2019, 01:36 PM
  2. [SOLVED] Macros in different sheets
    By JulijaKT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-02-2016, 06:59 AM
  3. [SOLVED] Macros in protected sheets
    By edmundo1971 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2013, 02:07 PM
  4. macros to auto name sheets
    By bdaniel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-29-2013, 03:51 PM
  5. How to use MACROS from different sheets
    By gs30 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-20-2009, 08:10 PM
  6. hiding sheets but still letting macros run when printing hidden sheets
    By stevesunfold in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 11-13-2008, 04:35 AM
  7. Macros-creating new sheets
    By Bonbon in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-17-2006, 05:50 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