Consulting

Results 1 to 3 of 3

Thread: Selecting Sheet via Input Box or other way

  1. #1

    Selecting Sheet via Input Box or other way

    my apologies for poorly wording the thread title but i have yet to actually determine a possible way of performing this function

    i need to be able to Set a variable to specific worksheet. possibly via Input Box or some other form

    are there any other such ways of propting a user to choose a worksheet [or also row or column] besides an input box? thank you!

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    well here is a method:

    Private Sub ListBox1_Click()
    Dim WS As Worksheet
    With Me.ListBox1
       Set WS = Worksheets(.List(.ListIndex))
       MsgBox "You selected - " & WS.Name
    End With
    WS.Select
    Set WS = Nothing
    End Sub
    
    Private Sub UserForm_Initialize()
    Dim WS As Worksheet
    Dim WB As Workbook
    Set WB = ThisWorkbook
    For Each WS In WB.Worksheets
       Me.ListBox1.AddItem WS.Name
       Next WS
       Set WS = Nothing
       Set WB = Nothing
    End Sub


    Create a form and add a Listbox to it and paste the code to it.
    Last edited by Aussiebear; 04-09-2023 at 04:42 PM. Reason: Adjusted the code tags

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    If you want an InputBox.

    Dim uiSheet as Worksheet
    On Error Resume Next
    Set uiSheet = Application.InputBox("Select a cell on the key sheet.", type:=8).Parent
    On Error Goto 0
    If uiSheet Is Nothing Then
      MsgBox "canceled"
      Else
      MsgBox "You selected sheet " & uiSheet.Name
    End If
    Last edited by Aussiebear; 04-09-2023 at 04:43 PM. Reason: Adjusted the code tags

Posting Permissions

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