vba Range begins with active cell

Hanz77

Board Regular
Joined
Sep 21, 2006
Messages
87
I'm trying to select a range to begin with the active cell and go to the last row of column Q. Following is what I have so far and it works; however, the active cell will not always be cell "I9".

Dim LastRow As Long

LastRow = [A65536].End(xlUp).Row
Range("I9", Cells(LastRow, 17)).Select

The active cell will float between I2 and I30, but will always be somewhere in column I.

This seems like it should be easy, but I keep getting an error when I try to define a Dim for the active cell. Any thoughts on how to select a range between the active cell and the last row in column Q?

Regards,
Hanz
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Replace "I9" with activecell

Code:
Range(activecell, Cells(LastRow, 17)).Select

Also, check your code. 'Select' ing cells in VB is rarely necessary in order to perform actions on them

for instance

Code:
range("A1:B10").select
selection.copy

can be replaced with

Code:
range("A1:B10").copy
and it's usually faster

PS

use

Code:
LastRow = cells(rows.count,"A").end(xlup).row

rather than

Code:
LastRow = [A65536].End(xlUp).Row

as the former won't 'scale up' to versions of excel with more than 65536 available rows.
 
Upvote 0

Forum statistics

Threads
1,224,579
Messages
6,179,656
Members
452,934
Latest member
mm1t1

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