Select Sheet Array based on value of cells

mclambchop

New Member
Joined
Apr 29, 2014
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hello,

I want to select up to 12 sheets based on the value of a cell range. I have buttons that if selected will add a TRUE or if not selected a FALSE to range V12 t V32.

I then want to select the sheet names if the cell has a TRUE. I know what the code should look like but I cant figure out how to write the if part into it.

Sheets(Array("1", "2", "3", "4", "5", "6", "7", "8", "10", "11", "12")).Select


Could anyone help?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You have not told us which cells contain sheet names
VBA below assumes that column V holds TRUE/FALSE and column U contains the sheet names
- amend as required

Code:
Sub SelectSheets()
    Dim sheetArr() As String, i As Long, C As Range
    For Each C In Range("V12:V32")
        If C Then
            ReDim Preserve sheetArr(0 To i)
            sheetArr(i) = C.Offset(, -1).Value
            i = i + 1
        End If
    Next
    Sheets(sheetArr).Select
End Sub
 
Upvote 0
You have not told us which cells contain sheet names
VBA below assumes that column V holds TRUE/FALSE and column U contains the sheet names
- amend as required

Code:
Sub SelectSheets()
    Dim sheetArr() As String, i As Long, C As Range
    For Each C In Range("V12:V32")
        If C Then
            ReDim Preserve sheetArr(0 To i)
            sheetArr(i) = C.Offset(, -1).Value
            i = i + 1
        End If
    Next
    Sheets(sheetArr).Select
End Sub


That worked perfectly, thank you very much. Sorry, forgot to confirm where my sheet names where. I moved them to column U and works perfectly...
 
Upvote 0
Sorry, forgot to confirm where my sheet names where. I moved them to column U and works perfectly...

No need to apologise - I expected you to adjust the code not move your values!
(y)
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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