+ Reply to Thread
Results 1 to 10 of 10

Same macro to run in multiple worksheets

  1. #1
    Forum Contributor
    Join Date
    04-14-2017
    Location
    Auckland
    MS-Off Ver
    2016
    Posts
    119

    Same macro to run in multiple worksheets

    Dear Experts,

    I have a set of data in three worksheets and the macro i m using should run in three worksheets at a time from a single macro button in Sheet 1.

    The data that I have needs to be extracted from Column 3 and separate the values in () in Column 4 and the values in [] in column 5 and at the same time Column 3 needs to be refreshed and shown without the separated values.

    i posted this problem at https://www.excelforum.com/excel-pro...ml#post4631243 and Jindon gave me a solution as:

    Sub test()
    Columns(3).Copy Columns("b:c")
    Columns(3).Replace "(*)", "", 2
    Columns(3).Replace "[*]", "", 2
    Columns(4).Replace "*(", "", 2
    Columns(4).Replace ")*", "", 2
    Columns(5).Replace "*[", "", 2
    Columns(5).Replace "]*", "", 2
    End Sub

    But I can't make it happen for two other sheets at the same time. I wrote a code but its not working since I am novice and have very little idea about vb. I have not posted this problem in any other Forums. Thanks.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Same macro to run in multiple worksheets

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    04-14-2017
    Location
    Auckland
    MS-Off Ver
    2016
    Posts
    119

    Re: Same macro to run in multiple worksheets

    Thanks TMS but it extracted the whole thing to Column D and E. Column C has been refreshed and its okay but Column D has to pick only the values in Parenthesis (PERKG) and Column E has to pick only the values in Parenthesis [FISH]. Can you help me to get the solution? Thanks.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Same macro to run in multiple worksheets

    I edited and ran the code in your sample workbook. Whatever it did to one worksheet, I made it do it to all the worksheets.

    Adapt the principle to the code you actually want to run.

  5. #5
    Forum Contributor
    Join Date
    04-14-2017
    Location
    Auckland
    MS-Off Ver
    2016
    Posts
    119

    Re: Same macro to run in multiple worksheets

    When I run the code it gives me :

    139778 ATLAS ASDLO**** ORDER DETAILS ORDER DETAILS 23 YES
    139779 NANDOS ASDLO**** ASDLO**(PERKG)**[FISH] ASDLO**(PERKG)**[FISH] 55 NO
    139780 ATTRONS ASDLO**** ASDLO**(PERKTN)**[MEAT] ASDLO**(PERKTN)**[MEAT] 44 YES
    139781 VIDVEST ASDLO**** ASDLO**(PERKG)**[POULTRY] ASDLO**(PERKG)**[POULTRY] 33 NO
    139782 LORENZO ASDLO**** ASDLO**(PERKG)**[FISH] ASDLO**(PERKG)**[FISH] 22 YES

    But it should be:

    PO Number CUSTOMER NAME ORDER DETAILS QUANTITY INSPECTED
    139778 ATLAS ASDLO**** PERKG FISH 23 YES
    139779 NANDOS ASDLO**** PERKTN MEAT 55 NO
    139780 ATTRONS ASDLO**** PERKG POULTRY 44 YES
    139781 VIDVEST ASDLO**** PERKG FISH 33 NO
    139782 LORENZO ASDLO**** PERKG FISH 22 YES

    And it didn't change sheet 2 and Sheet 3 as well.

    Can you help me to sort it?

  6. #6
    Forum Contributor
    Join Date
    04-14-2017
    Location
    Auckland
    MS-Off Ver
    2016
    Posts
    119

    Re: Same macro to run in multiple worksheets

    I have cross posted this problem at http://forum.chandoo.org/threads/sam...ksheets.34102/ and looking for a solution very badly to save my job.

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Same macro to run in multiple worksheets

    If you need a solution that badly, this quickly, to save your job, things must be very bad indeed.
    I wish you the best of luck.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Same macro to run in multiple worksheets

    Ditto. Sounds like you have some sound advice across on the other forum. Good luck with that and, as they said over there, please update both forums with your final solution.

    On that note, (as they say on Dragon's Den,) I'm out.
    Last edited by TMS; 04-21-2017 at 06:29 PM.

  9. #9
    Forum Contributor
    Join Date
    04-14-2017
    Location
    Auckland
    MS-Off Ver
    2016
    Posts
    119

    Re: Same macro to run in multiple worksheets

    I have found a solution and given by Monty at Chandoo.org:

    Sub test()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Sheets
    ws.Select
    ws.Columns(3).Copy Columns("d:e")
    ws.Columns(3).Replace "(*)", "", 2
    ws.Columns(3).Replace "[*]", "", 2
    ws.Columns(4).Replace "*(", "", 2
    ws.Columns(4).Replace ")*", "", 2
    ws.Columns(5).Replace "*[", "", 2
    ws.Columns(5).Replace "]*", "", 2
    Next ws
    End Sub

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Same macro to run in multiple worksheets

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I'm not sure how that's different to my solution, other than it selects the ws worksheet which should not be necessary.

+ 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. Required Macro for combine multiple workbooks which contains multiple worksheets
    By DHANASEKARAN in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2013, 03:20 PM
  2. Macro to sum the product of multiple cells across multiple worksheets
    By ciayers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-08-2013, 03:28 PM
  3. [SOLVED] Macro to combine multiple cells from multiple worksheets into one worksheet
    By sharpmarc in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-20-2013, 02:42 PM
  4. Excel 2010 multiple worksheets print to multiple pdf 's is there a macro for this?
    By fontana in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2012, 01:40 PM
  5. Macro to print multiple worksheets to multiple PDFs.
    By ryanwood17 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-14-2010, 02:07 AM
  6. Macro to run for Multiple worksheets
    By sajeel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2009, 04:34 PM
  7. [SOLVED] Use a macro on multiple Worksheets
    By Bwoods in forum Excel General
    Replies: 1
    Last Post: 03-19-2006, 07:25 PM
  8. Macro for multiple worksheets
    By Amber in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2006, 05:00 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