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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error in VBA code (excel2007)

Status
Not open for further replies.

wmbb

Technical User
Jul 17, 2005
320
0
0
NL
What is wrong in the code below defining a range?

Code:
x=2
rng = Sheet1.Range(Cells(x, 2), Cells(x, 30))

 


Hi,

How is rng declared? It should be declared as a RANGE. Then...
Code:
Dim rng as range, x as long
x=2
[b][red]Set [/red][/b]rng = Sheet1.Range(Cells(x, 2), Cells(x, 30))
Is there a worksheet with a CodeName of Sheet1?



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
He Skip, Thanks for your quick response.
I just forgot "set"
Now it works like it should.

Thanks again.

 
For safety purpose I'd use full qualified objects:
Set rng = Sheet1.Range([!]Sheet1.[/!]Cells(x, 2), [!]Sheet1.[/!]Cells(x, 30))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top