selectin sheets based on value of cell

BrendanDixon

Board Regular
Joined
Mar 7, 2010
Messages
174
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,

I have a worksheet that has a sheet called input and then sheets called 1, 2, 3, 4,5 all the way up to 30

I am using a macro to select all the sheets 1 to 30 but would like to make it more intelligent in that it will only select the sheets based on whether a cell has a value or is empty.
Code:
Sheets(Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30")).Select
Basically I want if Cell C9 has a value it will select sheet "1", D9 will select sheet "2" all the way to AF9 will select sheet "30"
 
Try

Code:
Sub test()
Dim i As Long, Got As Boolean
For i = 1 To 30
    If Sheets(CStr(i)).Range("C9").Value <> "" And Sheets(CStr(i)).Range("C9").Value <> 0 Then
        If Not Got Then
            Sheets(CStr(i)).Select
            Got = True
        Else
            Sheets(CStr(i)).Select Replace:=False
        End If
    End If
Next i
If Not Got Then
    MsgBox "No data"
    Exit Sub
End If
End Sub
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
PERFECT!!!!!!!


Thanks so much VoG I have been wanting to do this for such along time.


Thanks!!!
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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