Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error '91: Object variable or with block variable not set

Status
Not open for further replies.

cboz

Technical User
Dec 24, 2002
42
US
in excel 2007

i want to be able to enter a single cell address then execute some code. here is what i have tried.

Dim MyCell As Range

MyCell = InputBox("Enter Beginning Cell i.e. A1")

Range("MyCell").Select 'this is where the error occurs
 



hi,
Code:
Dim MyCell As [b]String[/b]

MyCell = InputBox("Enter Beginning Cell i.e. A1")

Range(MyCell).Select   'no QUOTES

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
thanks that worked. i had tried String earlier but i still had the quotes.
 
Hi cboz,

that is because you dim MyCell as a Range, i.e. as an Object, but try to assign a string value to it.
Then you put this MyCell as argument into Range(), and you do so enclosing it with quotes.
That however means that you try to select a Range that is named "MyCell" - and this Range does not exist.

1.) try this instead:
Code:
Dim MyCell as Range, inp as String
inp=InputBox("Enter Beginning Cell i.e. A1")
[b]Set MyCell=Range(inp)[/b]

2.) what are you trying to achieve? You should avoid SELECTing ranges within code when possible. Most things can be achieved without selecting the range.

Cheers,
MiS

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Oopsy, took too long it seems.
[tongue]

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 


I agree with MakeItSo item 2) also.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top