ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   have a macro recognize added rows (https://www.excelbanter.com/excel-programming/394779-have-macro-recognize-added-rows.html)

Mike M.

have a macro recognize added rows
 
I have written a macro to change the cell format over several speciffic
ranges. Two if the ranges are meant to be flexible by added rows. The macro
as an absolute value default does not recognize the added rows and as a
result the format changes in the wrong area. Is there a work around here? A
way to have the macro flex when the rows are added?

Jim Thomlinson

have a macro recognize added rows
 
The following code will give you the last populated row in Column A on
sheet1. Knowing that you should be able to get your range sorted out. Your
range to format can alse be defined strictly using range objects whish would
probably be more efficient but it also requires a greater understanding...

dim lngLastRow as long

lnglastrow = worksheets("Sheet1").Cells(rows.count, "A").End(xlUp).row
msgbox lngLastRow
--
HTH...

Jim Thomlinson


"Mike M." wrote:

I have written a macro to change the cell format over several speciffic
ranges. Two if the ranges are meant to be flexible by added rows. The macro
as an absolute value default does not recognize the added rows and as a
result the format changes in the wrong area. Is there a work around here? A
way to have the macro flex when the rows are added?


Jim Cone

have a macro recognize added rows
 

You could use a named range.
Rows inserted into a named range expand the range...
Range("FlexRange").Interior.ColorIndex = 40
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Mike M." <Mike
wrote in message
I have written a macro to change the cell format over several speciffic
ranges. Two if the ranges are meant to be flexible by added rows. The macro
as an absolute value default does not recognize the added rows and as a
result the format changes in the wrong area. Is there a work around here? A
way to have the macro flex when the rows are added?

Jim Thomlinson

have a macro recognize added rows
 
For that Mike you may want to use a dynamic named range...

http://www.cpearson.com/excel/named.htm
--
HTH...

Jim Thomlinson


"Jim Cone" wrote:


You could use a named range.
Rows inserted into a named range expand the range...
Range("FlexRange").Interior.ColorIndex = 40
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Mike M." <Mike
wrote in message
I have written a macro to change the cell format over several speciffic
ranges. Two if the ranges are meant to be flexible by added rows. The macro
as an absolute value default does not recognize the added rows and as a
result the format changes in the wrong area. Is there a work around here? A
way to have the macro flex when the rows are added?



All times are GMT +1. The time now is 01:51 PM.

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