Using VBA select sll sheets based on Criteria on each sheet.

A

AirgasRob

I know how to select all sheets but need to be able to filter which sheets I
want selected. Can I select a sheet in a workbook based on criteria in a
specific cell?

This is the code I used to select all sheets.

Dim arySheets
Dim sh
Dim i As Long

ReDim arySheets(ActiveWorkbook.Worksheets.Count - 1)

For Each sh In ActiveWorkbook.Worksheets
arySheets(i) = sh.Name
i = i + 1
Next sh
Sheets(arySheets).Select
 
J

Jim Thomlinson

Try this...

Dim arySheets() as string
Dim sh as worksheet
Dim i As Long

ReDim arySheets(ActiveWorkbook.Worksheets.Count - 1)

For Each sh In ActiveWorkbook.Worksheets
if sh.range("A1").value = "Tada" then
arySheets(i) = sh.Name
i = i + 1
end if
Next sh
ReDim preserve arySheets(i-1)
Sheets(arySheets).Select
 
R

Rick Rothstein

Jim has given you what looks like a solution to your question... I just
wanted to point out that if you want to select all the worksheets in the
active workbook, you can use this single line of code to do that...

ActiveWorkbook.Worksheets.Select
 
A

AirgasRob

Hi Jim thank you for the response. I ran the code this morning and got a code
break at

ReDim Preserve arySheets(i - 1)
 
A

AirgasRob

Never mind I figured it out, the criteria has to be exact for example; Yes
must be Yes not YES.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top