VBA to produce diologe box for user to select worksheet in workbook.

VBA learner ITG

Active Member
Joined
Apr 18, 2017
Messages
272
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello my peers,

I was wondering if anyone has come across a piece of code that can select open an excel file and list the tabs in the opened workbook in a diologe box for the user to select.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
.
Here is some of the code :

Code:
Private Sub UserForm_Initialize()


' Initialise user form
' Fill combo box with sheet names (start at 2)


Dim i As Long
Me.cmbListSheets.Clear
For i = 2 To Worksheets.Count
    Me.cmbListSheets.AddItem Worksheets(i).Name
Next i


End Sub


Private Sub cmbListSheets_Change()


' Check user selected something and enable Go button


If Me.cmbListSheets.Value <> "" Then


    Me.cmdGo.Enabled = True
    Me.cmdGo.Locked = False
    
Else


    Me.cmdGo.Enabled = False
    Me.cmdGo.Locked = True
    
End If


End Sub


Private Sub cmdCancel_Click()


'Unload form if cancel clicked


Unload Me


End Sub


Private Sub cmdGo_Click()


' Activate selected sheet


Dim ws As Worksheet


Set ws = ActiveWorkbook.Worksheets(Me.cmbListSheets.Value)


Unload Me
ws.Activate


End Sub

You can download the project here : https://www.amazon.com/clouddrive/share/sIYjhT955yKbJ9KxeLCasql4Vo2n8DdHPMmv3lUxcjv

This project does not include code for selecting a file first. Perhaps you can build on it ?
 
Upvote 0
This has now been resolved.

strMsg = "Choose the right sheet by number" & vbCrLf & vbCrLf
For Idx = 1 To wbCopyFrom.Worksheets.count
Set Sh = wbCopyFrom.Worksheets(Idx)
strMsg = strMsg & Idx & " => " & Sh.Name & vbCrLf
Next
res = CInt(InputBox(prompt:=strMsg, title:="Choose sheet to copy", Default:=1))
On Error Resume Next
Set wsCopyFrom = wbCopyFrom.Worksheets(res)
On Error GoTo 0
If wsCopyFrom Is Nothing Then
MsgBox "Wrong sheet number"
Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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