Select All Rows Between Two Rows in VBA

BetterBeef

New Member
Joined
Mar 18, 2010
Messages
42
Hello.

I want to be able to select rows 33 through rows 37 in VBA. I tried using the Union function, but this only selected rows 33 and 37. I want to select 33, 37, and everything in between. Is there a function that allows me to do this?

I want to do the equivalent of selecting row 33 with my mouse, holding the shift button down, and selecting row 37.

Any thoughts?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try

Code:
Rows(33 & ":" & 37).Select

but you should not need to select them in order to work with them.
 
Upvote 0
Yes, if

Actually I should be working on my projects and minding my own business but was curious for the ampersands when it looked like a hard coded question, which maybe it really isn't.
 
Upvote 0
That may have worked, but what I forgot to mention is that I am using two variables in the formula. Here is my formula:

report.Rows(SalesmanRow - LoopCount&":"&SalesmanRow - 1).Select

What am I doing wrong?

SalesmanRow is an Integer
LoopCount is an Integer

These are being set by a loop that I am running.
 
Upvote 0
OK, I figured out my problem. It always helps to actually have spaces between ampersands and variables. When I did that the code worked great! Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top