A very basic syntax question about ranges

Joined
May 6, 2011
Messages
25
The VBA line:

Range(Cells(Application.ActiveCell.SpecialCells(xlLastCell).Row, "E").Address).Select

works perfectly, selecting the cell in the "E" column of the last row in the worksheet with data in it.

So why doesn't the following select the range from E2 to that cell?

Range("E2:Cells(Application.ActiveCell.SpecialCells(xlLastCell).Row, "E").Address").Select

When I try it, I get a syntax error. I must be missing something blindingly obvious.
 
Then you could update to:

Code:
Sub SelectCells()
    Range("E2:E" & Range("A" & Rows.Count).End(xlUp).Row).Select
End Sub
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Neil,

Sorry, just saw your 12:22 reply.

Your code now gives me the same result that Jeffrey's used to: only cells E1-E2 are selected, not E2-E376.

(Note: the content of this sheet changes, and sometimes the E column is completely empty.)

Here are the codes that have worked so far:
Range("E2:E" & ActiveCell.SpecialCells(xlLastCell).Row).Select
Range("E2:E" & Cells.SpecialCells(xlLastCell).Row).Select
Range("E2:E" & Range("A" & Rows.Count).End(xlUp).Row).Select

These all select E2-E376.
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,476
Members
452,915
Latest member
hannnahheileen

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