ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamically select range (https://www.excelbanter.com/excel-programming/407500-dynamically-select-range.html)

Fatz

Dynamically select range
 
Hi-

I have a block of data, say A1:D10, and I have code that dynamically
selects what rows in column D I want to select. So one run may grab
D1:D6, and the next may grab D1:D8 depending on the
criteria....etc....

The problem I have is trying to select the entire block of data. So
if D1:D6 is selected, how do I then tell it to grab A1:D6? Currently
I use this code: Range(Selection,
Selection.End(xlToLeft)).Select....which is ok....until I get a break
in the range. So if column B is BLANK, the macro will only grab
columns C and D.

How do I tell the macro to grab an entire block of data, starting in
column A...and ending in the last row selected in column D??

Thanks,
Chris

Jim Thomlinson

Dynamically select range
 
with sheets(Sheet1)
.range(.range("D1"), .cells(rows.count, "A").end(xlup)).select
end with
--
HTH...

Jim Thomlinson


"Fatz" wrote:

Hi-

I have a block of data, say A1:D10, and I have code that dynamically
selects what rows in column D I want to select. So one run may grab
D1:D6, and the next may grab D1:D8 depending on the
criteria....etc....

The problem I have is trying to select the entire block of data. So
if D1:D6 is selected, how do I then tell it to grab A1:D6? Currently
I use this code: Range(Selection,
Selection.End(xlToLeft)).Select....which is ok....until I get a break
in the range. So if column B is BLANK, the macro will only grab
columns C and D.

How do I tell the macro to grab an entire block of data, starting in
column A...and ending in the last row selected in column D??

Thanks,
Chris



All times are GMT +1. The time now is 01:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com