Question posted 2013 · +7 upvotes
I want to allow a user to select a range that is likely to be in a different workbook.
I have attempted to do this with inputbox(“”,type:=8) which works to select data in the workbook but refuses to allow me to select a range in a different workbook.
Hence I would like a dialog box that allows me to perform this task.
Accepted answer +18 upvotes
Since I was free, I created an example for you
Create a Userform and place a ComboBox, A RefEdit Control and a Label

Next paste this code in the Userform
Private Sub UserForm_Initialize()
Dim wb As Workbook
'~~> Get the name of all the workbooks in the combobox
For Each wb In Application.Workbooks
ComboBox1.AddItem wb.Name
Next
ComboBox1 = ActiveWorkbook.Name
End Sub
'~~> This lets you toggle between all open workbooks
Private Sub Combobox1_Change()
If ComboBox1 <> "" Then Application.Workbooks(ComboBox1.Text).Activate
Label1.Caption = "": RefEdit1 = ""
End Sub
'~~> And this lets you choose the relevant range
Private Sub RefEdit1_Change()
Label1.Caption = ""
If RefEdit1.Value <> "" Then _
Label1.Caption = "[" & ComboBox1 & "]" & RefEdit1
End Sub
This is what you get when you run the Userform



Excel VBA objects referenced (5)
ActiveWorkbook.Name— Refer to Named RangesActiveWorkbook.Name— Invalid procedure name errorApplication— Using events with the Application objectApplication— Working with Other ApplicationsApplication.Workbooks— Workbooks and Worksheets
Top excel-vba Q&A (6)
- How to clear the entire array? +58 (2010)
- How to change Format of a Cell to Text using VBA +55 (2011)
- Download attachment from Outlook and Open in Excel +43 (2012)
- Can a VBA function in Excel return a range? +36 (2009)
- 2 Dimensional array from range +34 (2013)
- Hiding an Excel worksheet with VBA +33 (2009)
excel-vba solutions on this site
— top 15%.