Dynamic pulldown of sheet names

ShadowRider

New Member
Joined
Sep 23, 2010
Messages
27
Office Version
  1. 365
Platform
  1. MacOS
  2. Web
I would like to create a dropdown that includes the names of all the sheets in the current workbook except the current one. In my case, I have 4 sheets labeled Sheet 1, Sheet 2, Sheet 3, and Calculations. I'd like to be able to select a sheet in the drop down, and have the value of the cell of the selected sheet put into a cell on the current sheet. I've tried to create examples with xl2bb:

Book1
A
11
Sheet1

Book1
A
12
Sheet2

Book1
A
13
Sheet3

Book1
AB
1Selected SheetValue in A1
2
3In cell A2 of this sheet, I'd like a drop down that contains the names of all sheets except 'Calculations' and I'd like the drop down to be dynamic so that when a new sheet is added, the drop down list will include it.In B2, I'd like the value of A1 in the sheet that is selected in the cell A2 of this sheet
Calculations


Thanks in advance.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
right click on the sheet that you want the drop-down in. select view code, and paste all the below into the module
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Me.Range("A2")) Is Nothing Then
        Call CreateSheetNamesDropDown
    End If
End Sub

Sub CreateSheetNamesDropDown()
    Dim ws As Worksheet
    Dim sheetList As String
    Dim dropDownCell As Range

    Set dropDownCell = ActiveSheet.Range("A2")
    
    For Each ws In ThisWorkbook.Sheets
       If ws.Name <> "Calculations" Then sheetList = sheetList & ws.Name & ","
    Next ws
    
    sheetList = Left(sheetList, Len(sheetList) - 1) ' Remove the trailing comma
    
    ' Apply Data Validation to the chosen cell with the sheet names
    With dropDownCell.Validation
        .Delete ' Remove any existing validation
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=sheetList
  
    End With
    
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Me.Range("A2")) Is Nothing Then
        Call DisplayMessage
    End If
End Sub

Sub DisplayMessage()
    [B1] = Worksheets([A2].Value).[A1]
End Sub
 
Upvote 0
Solution
I used most of what you have but I only had the task for b2 as an example of wanting to pull items with indirect. For that, I used
=INDIRECT("'"&A2&"'!A1")
instead which seems to work and I can expand for my obtaining other data on those pages.

Thank you very much.
 
Upvote 0

Forum statistics

Threads
1,222,759
Messages
6,168,049
Members
452,160
Latest member
Bekerinik

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