+ Reply to Thread
Results 1 to 9 of 9

Apply Module to Multiple Worksheets

  1. #1
    Registered User
    Join Date
    10-29-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    18

    Apply Module to Multiple Worksheets

    The code below clears the desired cells but only for the worksheet 'Spreadsheet'. I would like to perform the same function over a vast number of worksheets in my workbook. The worksheets I would like this to apply to are called 'Spreadsheet (2)', 'Spreadsheet (3)', 'Spreadsheet (4)', 'Spreadsheet (5)' etc. The other worksheets in the workbook called 'Overview', 'Summary' and 'Database' I would prefer this not to be applied to. I don't have very good knowledge of this aspect of excel so any advice on how to amend the module code below to clear the same cells in the similarly named worksheets would be appreciated.

    Sub Reset_Cells()

    Application.ScreenUpdating = False

    Sheets("Spreadsheet").Select

    Range("O6,O9,O11,O13").Activate

    Selection.ClearContents

    Range("A1").Select

    Application.ScreenUpdating = True

    End Sub
    Last edited by Celex005; 01-14-2015 at 12:03 PM.

  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,638

    Re: Apply Module to Multiple Worksheets

    Maybe this:

    Please Login or Register  to view this content.

    Regards, TMS
    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
    Registered User
    Join Date
    10-29-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Apply Module to Multiple Worksheets

    Thank you for your fast response TMS. I'm sure this is down to my inexperience, having copied and pasted your code into VBAProject > Modules > Module1 the clear cells function no longer appears to be working at all. Are there any more details which I can provide you with to help?

    If it is easier to apply the clear cells (O6, O9, O11 & O13) function to all worksheets in the workbook then that would be an alternative.
    Last edited by Celex005; 01-11-2015 at 05:31 PM.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Apply Module to Multiple Worksheets

    May be this line
    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-29-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Apply Module to Multiple Worksheets

    Thanks YasserKhalil, I noticed my mistake and made this correction before initially replying. This has been removed from the code above.
    Last edited by Celex005; 01-11-2015 at 05:36 PM.

  6. #6
    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,638

    Re: Apply Module to Multiple Worksheets

    The original was untested. However, it is now tested and it works, unchanged other than to remove the extraneous comma in the original range.

    Please see the attached sample workbook which I have created to test the code.

    On the Overview sheet, there are buttons to Reset and (Re)Fill the cells.

    Regards, TMS
    Attached Files Attached Files

  7. #7
    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,638

    Re: Apply Module to Multiple Worksheets

    Is the problem solved now?


    Regards, TMS

  8. #8
    Registered User
    Join Date
    10-29-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Apply Module to Multiple Worksheets

    Thank you very much for taking the time to put the attached xlsm together TMS. Due to my lack of knowledge of VBA I haven't been able to successfully get the macro to function as hoped. I have found an alternative approach which works well for me so please don't exhaust any more of your time on me or this problem.

    Best regards, Matt
    Last edited by Celex005; 01-14-2015 at 12:01 PM.

  9. #9
    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,638

    Re: Apply Module to Multiple Worksheets

    OK, please mark as solved.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Apply filter across multiple worksheets
    By sisterwolf in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-17-2016, 12:33 PM
  2. Apply filter across multiple worksheets
    By okkoos in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-31-2012, 02:37 AM
  3. [SOLVED] Apply same formula on multiple worksheets
    By Tanya1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-29-2012, 03:09 AM
  4. Module to apply to all open worksheets
    By nhojflies in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-14-2009, 12:13 PM
  5. Need to apply VBA code to multiple Worksheets
    By parteegolfer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2006, 04: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