Exclude one sheet name from "For Each ws In Worksheets"

GeeWhiz7

Board Regular
Joined
Nov 22, 2021
Messages
214
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi there,

I have a macro that walks through each worksheet in a workbook and gets data to collate into another workbook.
I would like to add another worksheet where I will analyze the data that has been collated.

How can I keep the analysis worksheet that I created after the initial macro run from being part of the "For Each ws In Worksheets" example if i run the macro again.

VB snippet. you can see I'm already not including the "Start Here" worksheet, but when I add an AND avoid the analysis worksheet, things don't seem to work very well.
Wondering if anyone knows a better way.

Thank you,

VBA Code:
    For Each ws In Worksheets
        If ws.Name <> "Start Here" Then
            If ws.UsedRange.Rows.count > maxRow Then
                maxRow = ws.UsedRange.Rows.count
                Set maxTickerWS = ws
            End If
        End If
    Next
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I didn't quite understand what you need.
Do you want to exclude multiple sheets?

Try this:

VBA Code:
  For Each ws In Worksheets
    Select Case ws.Name
      Case "Start Here", "Sheet1", "Sheet8"   'Excluded sheets
      
      Case Else
        If ws.UsedRange.Rows.Count > maxRow Then
          maxRow = ws.UsedRange.Rows.Count
          Set maxTickerWS = ws
        End If
    End Select
  Next
 
Upvote 0
Solution
I didn't quite understand what you need.
Do you want to exclude multiple sheets?

Try this:

VBA Code:
  For Each ws In Worksheets
    Select Case ws.Name
      Case "Start Here", "Sheet1", "Sheet8"   'Excluded sheets
     
      Case Else
        If ws.UsedRange.Rows.Count > maxRow Then
          maxRow = ws.UsedRange.Rows.Count
          Set maxTickerWS = ws
        End If
    End Select
  Next
I think I didn’t quite understand what I need either. Seems like I fix one thing only to create or find another flaw.
Your suggestion works, thank you!
 
Upvote 0
Im glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,042
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top