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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,563
Messages
6,125,565
Members
449,237
Latest member
Chase S

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