+ Reply to Thread
Results 1 to 17 of 17

running a macro on multiple sheets

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    running a macro on multiple sheets

    i need to run a macro on multiple sheets in a work book. the sheets (130 of them) start out with A,B,C. they run to Z and then repeat like AA,BB,CC all the way to ZZZZZ.

    i have tried to come up with something to start with but i am new to vbe and don't even have a game plan on this. the worksheet names are in a lookup table called "lookupABC123". the macro that runs basically copies from "A" a range and then does some editing and moving rows to a master sheet. i got the macro to run on 7 sheets but in the future, it could go to 130 sheets.

    any help would be appreciated.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: running a macro on multiple sheets

    So you want to run the code on every single sheet? If so:

    Please Login or Register  to view this content.
    Or, if there is/are certain sheets you don't wan the code to run on:

    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

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

    Re: running a macro on multiple sheets

    Can you share your working code and the Lookup Table Sheet?

  4. #4
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: running a macro on multiple sheets

    ok here is the formula workbook that has the lookup table in it.
    dont have any working code, not sure how to start this.

    http://www.filedropper.com/macrohelp

  5. #5
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: running a macro on multiple sheets

    so walruseggman, your code is helpful. but i need it to only do specific sheets, not all. the range of worksheets are A,B,C...X,Y,Z,AA,BB,CC...XX,YY,ZZ,AAA...ZZZ...AAAAA.....ZZZZZ, for a total of 130. how do i do that?
    Last edited by dmcgov; 11-23-2015 at 10:28 AM. Reason: added posters name

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: running a macro on multiple sheets

    So here is some basic code that i just recorded
    Sub COPYRANGE()
    '
    ' COPYRANGE Macro
    '
    '
    Sheets("A").Select
    Selection.Copy
    Sheets("MASTER").Select
    ActiveSheet.Paste
    End Sub

    basically my macro just copys a range from Sheet A to the Master sheet and pastes it. i need it to do this repeat multiple times, going from sheet A to B to C all the way to ZZZZZ. Note that there are other sheets in this workbook that it doesnt need to run on.

    thanks

    dan

  7. #7
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: running a macro on multiple sheets

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: running a macro on multiple sheets

    so why does this fail?
    Sub dmcgov()
    For Each ws In ThisWorkbook.Worksheets
    Set c = Sheets("Formulas").Range("K19:K148").Find(ws.Name, lookat:=xlWhole)
    If Not c Is Nothing Then
    Sheets(c).Select

    im referring to the last statement above. i get an error when i try to run the macro
    Last edited by dmcgov; 11-23-2015 at 11:58 AM.

  9. #9
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: running a macro on multiple sheets

    c is a Range (an object), not a string like a sheet name is. try:

    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: running a macro on multiple sheets

    thanks, that worked. now my simple macro needs some help. let me play around to see if i can get it fixed. but thanks walrusggman, you have gotten me further that i could do myself!!!

  11. #11
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: running a macro on multiple sheets

    Yeah, I don't understand your copy/paste code. Besides the fact that you don't need to be selecting sheets (it just slows things way down), it looks like you're selecting an entire sheet, then pasting over an already existing sheet. This would just "overwrite" MASTER every time. If you describe what ranges you're trying to copy, and where you want them pasted, I can help with the code.

  12. #12
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: running a macro on multiple sheets

    so, here is what happens in my macro. i go to the "A" tab, and select the range called estimate1. this gets copied to the estimating1 tab in location C2 and i paste the values as text. from there i copy two columns from estimating1 to master. then three more columns from estimating1 to master. then i do some formulas in different columns in the master tab. then i delete some rows and then sort the data. once done, then i copy over the master sheet to bigmaster (the next available row) and then delete the range in master and estimating1 and then go to tab "B". then repeat. does this help?

  13. #13
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: running a macro on multiple sheets

    I'd like to see a sample workbook. If you could post a small data set showing what the data looks like, and what you want it to look like after the code runs, that'd help immensely.

  14. #14
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: running a macro on multiple sheets

    ok here is the link to the workbook
    http://www.filedropper.com/macrohelp_1

    let me know

  15. #15
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: running a macro on multiple sheets

    I'd ask that you show me more flushed out sample data, along with an end result, because stuff like

    then three more columns
    and

    then i delete some rows and then sort the data
    aren't specific enough to write code for.

  16. #16
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: running a macro on multiple sheets

    well, as for the macro that runs inside each worksheet, i have that working with one exception. it doesnt copy one cell correctly. that you can help me with, all the rest i think it will be ok.

    so a little bit of background. when i copy the range from the A tab to the estimating sheet, i paste it into the page as text. one of the cells has data in it that says "Exhibit A". when i load up the B tab, the text will say "Exhibit B", with me so far? the problem is that when the macro runs, it copies into the macro the text that says "Exhibit A" on the A tab. if i run the macro on the B tab, it puts in "Exhibit A" into the cell but that is wrong, it should say "Exhibit B". the example below shows that the macro is recording the absolute text in the cell, when it should be using a relative "cell".

    ActiveCell.FormulaR1C1 = "Exhibit A"

    shouldnt it say something like" ActiveCell.FormulaR1C1 = cellA1.value (this is just a bad guess on my part, not knowing enough of VBA to sound competent)?

    if you need me to upload the entire macro and excel file, i can do that.

  17. #17
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: running a macro on multiple sheets

    i solved the problem above by doing the following:
    I named the range where "Exhibit A" is found and then did
    ActiveCell.FormulaR1C1 = "=Estimating1!Exhibit"

    i think that should fix the issue with the macro, thanks for all the 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. Question regarding running Macro across multiple sheets
    By whawk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-01-2014, 07:32 PM
  2. Running Same macro on Multiple sheets
    By shilpigupta79 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-01-2013, 03:29 AM
  3. Running Macro on multiple sheets
    By VKS in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-21-2013, 12:10 PM
  4. [SOLVED] Running Sub's in multiple other sheets
    By brhogan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2012, 02:58 AM
  5. Running macro in multiple sheets
    By shak1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-18-2009, 06:36 AM
  6. Running same VBA over multiple sheets
    By StuntMonkeh in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 01-14-2008, 05:43 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