Solved

run macro for selected sheets in workbook

Posted on 2014-01-05
5
1,270 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 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

815 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

13 Experts available now in Live!

Get 1:1 Help Now