+ Reply to Thread
Results 1 to 2 of 2

Macro on multiple sheets - grouped sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    09-23-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    1

    Macro on multiple sheets - grouped sheets

    I have a file that contains about 15 worksheets. Each sheet contains a chart that has the same number of rows and columns. My daily job task requires me to edit the chart by deleting rows, columns, and changing widths of columns for each worksheet I am responsible for. The fastest way I know how to do this was by grouping the sheets and then editing one of those charts on one of those sheets, and when I do this, it automatically formats all of sheets/charts at once. My question is this: is there a macro I can create to edit all of the sheets at once instead of me selecting/grouping the sheets first, then manually editing one of those grouped sheet's chart each time? I tried to record a macro for the grouped sheets, but when I ran it, it deleted all content of all sheets?

    I know if I recorded the same macro on only one sheet it would work, but it doesn't work on grouped sheets. I'm trying to figure out how to do this. Please help if you can.

    Thanks,

    Stan

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro on multiple sheets - grouped sheets

    Hi, Stan

    if you record a macro and work on that so that it fulfills the task you want you can run it on each worksheet of the workbook instead of grouping/ungrouping.

    Sub AllWorksheets()
    Dim ws As Worksheet
    
    Application.ScreenUpdating = False  'no flicker
    For Each ws In ActiveWorkbook.Worksheets
      ws.Activate
      Call StansMacro
    Next ws
    Application.ScreenUpdating = True
    End Sub
    
    Sub StansMacro()
    'put in the code you recorded and worked over
    End Sub
    If you need only certain sheets to work on you may use something like
    Sub CertainWorksheets()
    Dim ws As Worksheet
    
    Application.ScreenUpdating = False  'no flicker
    For Each ws In ActiveWorkbook.Worksheets
      Select Case ws.Name
        Case "Sheet1", "Sheet4", "Sheet7"   'change sheet names to suit
          ws.Activate
          Call StansMacro
        Case Else
      End Select
    Next ws
    Application.ScreenUpdating = True
    End Sub
    You can place that in your personl.xls or personal.xlsb to be on hand or inside the file if itīs always the same workbook you work on.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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