Using an Inputbox

NathanW

New Member
Joined
Jun 17, 2013
Messages
27
I've used inputboxes in the past and I do not know why I am having so much trouble now, but here is what I have:

Code:
Public StartCell As Variant
StartCell = Application.InputBox(Msg, "Select a Cell", Type:=8)
Range(StartCell).Activate

I am getting the error Run-time error '1004': Method 'Range' of object '_Global' failed.

Someone please help me!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Add the keyword Set:
Set Startcell
since you have used type:=8, VBA is looking for a range object in Startcell
 
Upvote 0
Thank you very much for your quick response, Joe. However, that did not work. I received the same error on the line "Range(Startcell).Activate" (which is where the error was before)
 
Upvote 0
After adding the Set as Joe suggested, just

Code:
StartCell.Select
 
Upvote 0
If it helps at all, I am noticing that when I hit "debug", the value in StartCell is "Empty". So it does not have a cell reference to activate? Not sure why it is doing that....
 
Upvote 0
If it helps at all, I am noticing that when I hit "debug", the value in StartCell is "Empty". So it does not have a cell reference to activate? Not sure why it is doing that....
Are you selecting a cell with your mouse when the input box appears?
 
Upvote 0
Yes, when the inputbox pops up, I select a cell on the screen and hit 'ok' on the inputbox, which is when the program crashes.
 
Upvote 0
Yes, when the inputbox pops up, I select a cell on the screen and hit 'ok' on the inputbox, which is when the program crashes.
Run this test and tell us if you get the msgbox.
Code:
Sub test()
Dim StartCell As Variant
On Error Resume Next
Set StartCell = Application.InputBox("Select a Cell", Type:=8)
On Error GoTo 0
If Not StartCell Is Nothing Then
    MsgBox "StartCell is cell " & StartCell.Address
    StartCell.Select
End If
End Sub
If yes, then note that your original post showed InputBox(Msg, ...)
and you should either define Msg as a string and initialize it or remove it.
 
Last edited:
Upvote 0
That made it work! Thank you guys so much for your help and persistence. Any idea why it took all that error handling to make it work? I don't understand why this had to be so complicated =P
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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