Results 1 to 3 of 3

Thread: Data Validation With Dynamic List Of Sheet Names

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    14
    Rep Power
    0

    Data Validation With Dynamic List Of Sheet Names

    Hi,

    Intro cell with data validation I want to have all the sheet names (except the first sheet), but dynamic. I mean if you add or delete a worksheet, I want to see this in cell with data validation.

    Example:
    I have 10 sheets in my file (Sheet1 to sheet 10) in cell M3 is data validation and there we can choose any piece between 2 and 10. If you add 2 sheets in M3 can choose between sheet 2 and 12.
    Conversely if I delete 5 sheets in M3 I wish I could choose between sheet 2 to 5.

    How can I do this? Thanks.

  2. #2
    Junior Member
    Join Date
    Aug 2013
    Posts
    6
    Rep Power
    0
    Hi,

    Right click Sheet 1 tab, view code and paste this code in on the right. I have used Z2:Zn to build the dynamic list of sheet names and this list is re-created every time you click in M3 of sheet 1. If you want to use a different range then ensure you start in Row 2 of which ever column you choose.

    Code:
    Private Sub Worksheet_Activate()
    If ActiveCell.Address = "$M$3" Then
        ActiveCell.Offset(-1).Select
    End If
    End Sub
    
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim x As Long
    If Target.Address <> "$M$3" Or Target.Cells.Count > 1 Then Exit Sub
    For x = 2 To Worksheets.Count
        Cells(x, "Z") = Sheets(x).Name
    Next
    With Target.Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=$Z$2:$Z$" & x - 1
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    
    End Sub
    Last edited by Mike H; 08-19-2013 at 01:52 AM.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    14
    Rep Power
    0
    Mike, thank you very much.
    Have a good day.

Similar Threads

  1. Replies: 2
    Last Post: 07-28-2013, 09:29 AM
  2. Replies: 4
    Last Post: 07-27-2013, 01:34 PM
  3. VBA Validation List set
    By xander1981 in forum Excel Help
    Replies: 3
    Last Post: 02-15-2013, 04:07 PM
  4. Display sheet names in a message box
    By pells in forum Excel Help
    Replies: 4
    Last Post: 02-13-2013, 07:33 PM
  5. List all Worksheet Names Using Formula
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 6
    Last Post: 12-17-2012, 02:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •