Solved

run macro for selected sheets in workbook

Posted on 2014-01-05
5
1,427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 27

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 27

Expert Comment

by:MacroShadow
ID: 39758592
Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

738 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