ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting sheets based on cell in each sheet (https://www.excelbanter.com/excel-programming/369325-selecting-sheets-based-cell-each-sheet.html)

Steve

Selecting sheets based on cell in each sheet
 
If I have a "Yes" or "No" in say cell A1 of each sheet in a workbook. Is
there a way to select each sheet that has a "Yes" in cell A1? There could be
up to 100 sheets in the workbook. Thanks for any help.

Excelenator[_41_]

Selecting sheets based on cell in each sheet
 

This code will do what you ask


Code:
--------------------
Private Sub test()
Dim w As Worksheet
Dim ws() As String
Dim i As Integer

i = 0

For Each w In Worksheets
If UCase(w.Range("A1").Value) = "YES" Then
ReDim Preserve ws(i)
ws(i) = w.Name
i = i + 1
End If
Next w

Sheets(ws).Select

End Sub
--------------------


--
Excelenator


------------------------------------------------------------------------
Excelenator's Profile: http://www.excelforum.com/member.php...o&userid=36768
View this thread: http://www.excelforum.com/showthread...hreadid=568108


Steve

Selecting sheets based on cell in each sheet
 
Thank you very much, that worked perfectly.

"Excelenator" wrote:


This code will do what you ask


Code:
--------------------
Private Sub test()
Dim w As Worksheet
Dim ws() As String
Dim i As Integer

i = 0

For Each w In Worksheets
If UCase(w.Range("A1").Value) = "YES" Then
ReDim Preserve ws(i)
ws(i) = w.Name
i = i + 1
End If
Next w

Sheets(ws).Select

End Sub
--------------------


--
Excelenator


------------------------------------------------------------------------
Excelenator's Profile: http://www.excelforum.com/member.php...o&userid=36768
View this thread: http://www.excelforum.com/showthread...hreadid=568108




All times are GMT +1. The time now is 03:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com