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

Range Syntax

Status
Not open for further replies.

Mantle51

Programmer
Aug 17, 2006
97
US
Hello,

I have the following code which works but I don't know why it doesn't cause an error.

Dim rng As Range, k as Integer
k = InputBox("Enter Start Row")

Set rng = Range("B" & k, [B2].End(xlDown)) >>This works, but when I try to substitute the second [B2] with ["B" & k], it will not run.

Hypothetically, if k=10, then how can the logic be correct?

 
I generally stay away from shorthand notation (that is keeping the range reference in [] square brackets) and you can't mix/match numbers with that type of notation either. Instead, use ...

Code:
Dim rng As Range, k as Integer
k = InputBox("Enter Start Row")

Set rng = Range("B" & k, Range("B" & k).End(xlDown))

HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top