View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default application.inputbox

Couldn't figure that out myself when I had to do it a little while ago, so
I'm also interested in other folks response. I resorted to a two-step
process:

I ended up creating a userform w/a dropdown box listing all of the open
workbooks. When the OK button was clicked the value from the combobox is
saved to a public variable and the userform is unloaded. Then the code
activates the target workbook and the inputbox prompts the user to select the
range. I'm sure there's a better way, but the macro was for my own use and
the destination worksheet and range don't change - so all I really needed was
the target workbook.

Code for the command button and combobox from the userform

Private Sub CommandButton1_Click()
wkbDest = Me.ComboBox1.Value
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim wkbTemp As Workbook
For Each wkbTemp In Workbooks
Me.ComboBox1.AddItem wkbTemp.Name
Next wkbTemp
End Sub


code for the macro:

Public wkbDest As String

Sub test()
Dim rngDest As Range

wkbDest = ""
UserForm1.Show
Workbooks(wkbDest).Activate
Set rngDest = Application.InputBox("Enter Range", Type:=8)
ThisWorkbook.Activate
rngDest.Value = "Testing"
End Sub


I didn't include any error handling, so you may want to look at that.



"Christmas May" wrote:

I'm attempting to have my VBA pause for the user to enter a range. I've used
application.inputbox(prompt:="Enter range", type:=8) which works great as
long as the user is planning to select a range in the current workbook.

Does anyone have a suggestion for allowing the user to select a range in a
different workbook?

Thanks in advance,

Christmas May