简体   繁体   中英

Freeze rows in a Macro to stop Hide/ Unhide moving when rows are added above in excel spreadsheet

I have very basic knowledge. I have a tick box which when ticked unhides certain rows? Is there a way of freezing the rows in the code so that if a row is inserted or deleted above in the excel shett the macro recognizes the movement in row numbers? In an excel formula I would use $

   'hide or unhide Row:
Sheet1.Rows("123:115").Hidden = Not (CheckBox1.Value)

Any help would be appreciated

Create a range name eg MyRows equal to 115:123 (entire rows).

In your code:

 [MyRows].EntireRow.Hidden = True  #Hide rows
 [MyRows].EntireRow.Hidden = False #UnHide rows

It is impervious to insert/delete rows as long as you don't select a row in the range when you do the insert/delete.

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM