Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Run Time Error 424 - Object Required

  Asked By: Leon    Date: Dec 11    Category: MS Office    Views: 1334
  

Just starting with Excel VBA and have had a lot help reading
through the posts here.

I get stuck on this snipped of code, could somebody help me out
please?
--------------
Option Explicit
Dim obRange1 As Object
Dim obRange2 As Object

Sub MergeLists()
Set obRange1 = Application.InputBox(prompt:="Select first range of
data", Type:=8)
End Sub
--------------
After selecting range and clicking ok I get run-time error 424.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Garry Sanchez     Answered On: Dec 11

InputBox returns a string, not an actual range, so you'll need to first
return the result to a string and then turn that into a range.

How about:

Option Explicit
Dim obRange1 As Range ' <- change
Sub MergeLists()
Dim s as string
s = Application.InputBox(prompt:="Select first range of data", _
Type:=8)
Set obRange1 = ActiveWorkbook.ActiveSheet.Range(s)
obRange1.Select ' If you want to select the specified range.
End Sub

 
Answer #2    Answered By: Chung Tran     Answered On: Dec 11

Copy-pasting your code into the module returns Run-time Error 13 (Type
mismatch).

 
Answer #3    Answered By: Salvador Alexander     Answered On: Dec 11

So sorry for the slow reply, and also the wrong info.

I never noticed the Type parameter to InputBox in Excel, so my answer to
you was bogus.

My code works correctly if you set Type:=2 (text).

On the other hand, on my machine, your original code works perfectly.
You can test it by selecting the range, so maybe like this:

Option Explicit
Dim obRange1 as Range
Sub MergeLists2()
Set obRange1 = Application.InputBox(prompt:="Select first range of data
", Type:=8)
obRange1.Select
End Sub

I'm not sure why it doesn't work for you! Did you try doing it in a
completely new workbook?

 
Answer #4    Answered By: Andrew Bryant     Answered On: Dec 11

Pasted into new module and added the .Select

 
Didn't find what you were looking for? Find more on Run Time Error 424 - Object Required Or get search suggestion and latest updates.




Tagged: