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

Rows Method in VBA for Excel

Status
Not open for further replies.

Numbers1

Technical User
Dec 27, 2003
34
US
I want to replace specific row references in the Rows Method with variables and can not figure out the format. The format as shown in help is:
Rows("10:11").Select
This code selects the 10th and 11th rows specifically. I tried using variables instead of the row references as follows:
Dim intRow as Integer
Dim intRow1 as Integer

Rows(intRow:(intRow + 1)).Select
Also tried:
Rows(intRow:intRow1).Select

Both brought up an error indicating that the Colon was wrong. Can anyone help?
Thanks, Numbers
 
This should work

Code:
m=6 : n = 10 
Rows(m & ":" & n).select

Dave
 

I think it would be better to use:

m=6 : n = 10
Range(rows(m),rows(n)).select

 
Just curious, why is it "better" ?

I was showing Numbers1 how to incorporate the ':' w/o getting an error message. Is there a case that this won't work ?
 
Personally, I don't think it is - it just depends what you are comfortable with - I use
rows(x & ":" & y) syntax a fair amount - it's the same as using
Range("A1") or cells(1,1)

No real difference, just different syntax

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 

I did say "I think"!!...

In my opinion it seems better practice not to concatenate to make a string for the range reference when this does not need to be done.

Other things I think are that you should use the Cells method rather than putting the address of the range in brackets, and that you should avoid using "Offset" in VBA Code, especially when looping. (I heard this from a real pro, that's why!)


 
Hi,

LOTS of ways to skin a cat.

Here's another...
Code:
m=10
n=12
range(cells(m, 1), cells(n, 1)).entirerow.select
:)

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
WOW! I didn't expect this type of feedback. This was my first post and the responses given by all of you are great! Never expected to get this type of response. Thank you all for the solutions to my question.
Numbers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top