ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   VBA, identify a range (https://www.excelbanter.com/excel-worksheet-functions/38314-vba-identify-range.html)

Danny

VBA, identify a range
 
I am writing a macro for sorting my worksheet. My macro would select a named
range, for instance the named range is A15. Then I go up one cell to A14 and
select A14 to E 14. The macro would read: Range("A14:E14").Select.

When I add more rows and go to the named range and go up one cell, the row
is no longer Row 14. How do I write the macro for this?

Bernie Deitrick

Range("NamedRange").Offset(-1,0).Resize(1,5).Select

HTH,
Bernie
MS Excel MVP


"Danny" wrote in message
...
I am writing a macro for sorting my worksheet. My macro would select a named
range, for instance the named range is A15. Then I go up one cell to A14 and
select A14 to E 14. The macro would read: Range("A14:E14").Select.

When I add more rows and go to the named range and go up one cell, the row
is no longer Row 14. How do I write the macro for this?




Bob Phillips

Set rng = Range("range_name").Offset(-1,0).Resize(1,5)
rng.Sort etc.


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Danny" wrote in message
...
I am writing a macro for sorting my worksheet. My macro would select a

named
range, for instance the named range is A15. Then I go up one cell to A14

and
select A14 to E 14. The macro would read: Range("A14:E14").Select.

When I add more rows and go to the named range and go up one cell, the row
is no longer Row 14. How do I write the macro for this?





All times are GMT +1. The time now is 03:34 AM.

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