Solved

run macro for selected sheets in workbook

Posted on 2014-01-05
5
1,164 Views
Last Modified: 2014-01-05
Hello,

the macro below runs for all the sheets in Wb"A".

Can one change it so that it runs for only for the selected sheets with names sheet1, sheet2, sheet6 and sheet10

Thanks,
CC

Sub processAllSheets()

    Dim iSheet As Worksheet

For Each iSheet In Workbooks("A.xlsx").Sheets
     Call CopyRowsByDate(iSheet.Name)
Next iSheet

End Sub
0
Comment
Question by:CC10
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Steven Harris
ID: 39757977
This is the part that is looking at all sheets:

Dim iSheet As Worksheet

For Each iSheet In Workbooks("A.xlsx").Sheets

Open in new window


You would want to do something like:

Sub processAllSheets()

Dim iSheet
iSheet = Array(Sheet1, Sheet2, Sheet6, Sheet10)

For Each iSheet In Workbook
     Call CopyRowsByDate(iSheet.Name)
Next iSheet

End Sub

Open in new window

0
 
LVL 26

Accepted Solution

by:
MacroShadow earned 300 total points
ID: 39757992
Option Explicit

Sub processAllSheets()

    Dim iSheet As Worksheet

    For Each iSheet In Workbooks("A.xlsx").Sheets
        Select Case iSheet.Name
            Case "sheet1", "sheet2", "sheet6", "sheet10"
                Call CopyRowsByDate(iSheet.Name)
        End Select
    Next iSheet

End Sub

Open in new window

0
 

Author Comment

by:CC10
ID: 39758590
I was unaware that the A grade was the default and awarded the B grade as I thought it was a relatively simple and uncomplicated question.
If you wish I can change it to an A grade but how do I do that.

CC
0
 
LVL 26

Expert Comment

by:MacroShadow
ID: 39758592
Thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will show you how to use shortcut menus in the Access run-time environment.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now