Selecting range of cells with variable row

riggsd

Board Regular
Joined
Jan 29, 2003
Messages
143
I need to be able to select a range of cells where the row number is a variable, endRow.

How do I select the cells from (endRow, 1) through (endRow, 5)?

If I knew the row, I could put something like, Range("A20:E20").Select, but I don't know how to modify that when the row numbers aren't known.

Thanks in advance.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this.
Code:
Range("A" & endRow & ":E" & endRow).Select

By the way why are you selecting the cells?
 
Upvote 0
They're being selected because I need to merge them.

What I'm doing is automating some reports. The data in these rows comes out in one cell per row and needs to be merged in across columns A through E to follow the required format. Each report has a different number of these rows, hence the variable row number.

I'm trying Kristy's code since that's closer to what the rest of my stuff uses. So far, VBA is accepting it.

Thx.
 
Upvote 0
You don't need to select ranges to work with them.
Code:
Range(Cells(endrow, 1), Cells(endrow, 5)).Merge
 
Upvote 0
On a similar issue, how do I select rows using variables? I need to select the rows from startRow to endRow and move them to another worksheet.
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,509
Members
448,967
Latest member
screechyboy79

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