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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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

Forum statistics

Threads
1,224,814
Messages
6,181,120
Members
453,021
Latest member
Justyna P

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