+ Reply to Thread
Results 1 to 6 of 6

Run macro on different sheets

  1. #1
    Registered User
    Join Date
    10-23-2013
    Location
    athens
    MS-Off Ver
    Excel 2003
    Posts
    10

    Run macro on different sheets

    Hi guys

    I managed to create the below code in order to hide empty columns

    Sub Auto_Open
    Set r = ActiveSheet.UsedRange
    nLastColumn = r.Columns.Count + r.Column - 1
    nFirstcolumn = r.column
    For n = nFirstcolumn To nLastcolumn
    If Application.WorksheetFunction.CountA(columns(n)) = 0 Then
    columns(n).Entirecolumn.Hidden = True
    End If
    Next
    End Sub


    as you see i named Auto_open so it starts at the opening, but i set it for active sheet
    My workbook contains 7 sheets and i would like this macro to run at the beginning for sheets 2 kai 5. (i have renamed these sheets )

    Any help??

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run macro on different sheets

    This would run the code on the worksheets 2 to 5.
    Please Login or Register  to view this content.
    PS Can you use code tags when posting code?
    [/code]
    If posting code please use code tags, see here.

  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: Run macro on different sheets

    Maybe a workbook sheet activate event will work?

    Please Login or Register  to view this content.
    Change Sheet2 and Sheet3 in the code too the sheets you don't want the macro to operate on.

  4. #4
    Registered User
    Join Date
    10-23-2013
    Location
    athens
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Run macro on different sheets

    Norie thank you very much for your prompt reply.
    The code works fine but doesn't auto start at the beginning

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run macro on different sheets

    Try this code, which goes in the ThisWorkbook module.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-23-2013
    Location
    athens
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Run macro on different sheets

    fixed it! thanks!!! I was saved the code on a sheet i just moved it in a module.
    You were both very helpful . Thank again

+ 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. Replies: 2
    Last Post: 09-19-2013, 04:22 AM
  2. [SOLVED] Macro to Unprotect sheets-unlock range of cells-protect sheets
    By jrace in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2013, 10:45 AM
  3. Creating a macro to print only the sheets and portion of sheets that i select.
    By cadamhill in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-31-2012, 01:48 PM
  4. Replies: 0
    Last Post: 10-10-2012, 08:56 AM
  5. [SOLVED] Macro for filter on protected workbook that works for all sheets, no matter what sheets are named?
    By StargateFanFromWork in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-26-2006, 02:35 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