VBA dialog box for selecting a range in different books

I want to allow the user to select a range that may be in another book.

I tried to do this with inputbox ("", type: = 8), which works to select data in a workbook, but does not allow me to select a range in another workbook.

Therefore, I would like the dialog box to allow me to perform this task.

+7
excel-vba excel range dialog
source share
1 answer

Since I was free, I created an example for you

Create a Userform and place the ComboBox , A RefEdit and Label control

enter image description here

Then paste this code into 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 start Userform

enter image description here


enter image description here


enter image description here

+19
source share

All Articles