+ Reply to Thread
Results 1 to 16 of 16

Running a macro over numerous sheets

  1. #1
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Running a macro over numerous sheets

    The below code works great on one sheet, but how can I alter it so that it runs on Sheet1, Sheet2, Sheet3, Sheet4, Sheet5, Sheet6 and Sheet7. I know I could copy and paste the code 7 times and point it to the worksheets but I am sure there is an easier way?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Running a macro over numerous sheets

    Hello,
    Like this, if the sheets are the first 7 in you workbook :

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Running a macro over numerous sheets

    They are not the first 7 in my workbook though. They are scattered around between other sheets with names.

  4. #4
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Running a macro over numerous sheets

    Ok then, use this method instead :
    (name the sheets were indicated)

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Running a macro over numerous sheets

    Brilliant.

    This part is a bit more complex but only realising I need it now - How would I alter it so that it only color fills the word if column D contain one of the words AND column E contained another specified word.

    So for example, if the set of words in column D were like the ones in the code, I would want it to fill the cell in color if it found one of those words in column D BUT also found a word that I specify in the column directly to the right of where the word was found.

    So in my code word1 for column D is 'Alkan', but I'd only want Alkan to highlight in column D if column E on the same row contained the word 'America'

  6. #6
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Running a macro over numerous sheets

    Can you be more precise...

    Do you have multiple words possible in column E?
    Are they different for each word in column D?

  7. #7
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Running a macro over numerous sheets

    I want col D to highlight if col D contains one of the words listed above in the code but ONLY if col E contains another word I specify.

    The word in col E would be specific to the word in Col D. So if col D contained 'Alkan' then I'd only want it to highlight if col E contained 'America'.

  8. #8
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Running a macro over numerous sheets

    If you specify one word at a time then :

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Running a macro over numerous sheets

    OK, so instead of the input box, if "MS" is found in col D then if col E contains 'Germany' then I want it to color. If 'Alkan' is found is col D then if col E contains 'Britain' I want it to color, and so on. Can this be done?

  10. #10
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Running a macro over numerous sheets

    Can you add a tab in your workbook that would contain the data ?
    For example in column A, you would have MS, Alkan, J2, ...
    And in column B, you would have : Germany, Britain, ...

  11. #11
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Running a macro over numerous sheets

    I''d rather not have the data on an actual tab in the workbook. Surely it's possible to just place the words in the code itself?

  12. #12
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Running a macro over numerous sheets

    Yes, like this :
    Make sure you have the same number of arguments in WordsD and WordsE arrays.
    If you don't want to highlight the cells if column E is empty, replace "" by some dummy text in WordsE array.

    Please Login or Register  to view this content.

  13. #13
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Running a macro over numerous sheets

    I'll give that a go now. Just to confirm, in your code above, if col D is MS and E is Germany it will highlight, but if col D is MS and E is Britain it will NOT highlight?

  14. #14
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Running a macro over numerous sheets

    Works perfectly. How do I change it so it highlights both Col D and E instead of just D and I will be finished!

  15. #15
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Running a macro over numerous sheets

    Excellent !

    Replace :

    Please Login or Register  to view this content.
    by
    Please Login or Register  to view this content.

  16. #16
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Running a macro over numerous sheets

    Thanks GC. Much appreciated.

+ 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. Running Same macro on Multiple sheets
    By shilpigupta79 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-01-2013, 03:29 AM
  2. Running Macro on Protected Sheets
    By What's it doing in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2010, 01:24 PM
  3. Match Name Numerous Sheets
    By Killer17 in forum Excel General
    Replies: 2
    Last Post: 02-03-2009, 08:25 AM
  4. Macro to format numerous sheets into one
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-18-2007, 05:35 AM
  5. propogating cells with data from numerous sheets
    By G. Beard in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-03-2005, 07:05 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