RegularExcelUser
New Member
- Joined
- Apr 6, 2023
- Messages
- 25
- Office Version
- 365
- Platform
- Windows
Hi there, I've been building a spreadsheet to replicate how a piece of billing system functionality works. To that end, if you click certain buttons in the system, it will hide all subsequent options. To that end, I've a piece of VBA code running that replicates this for me e.g. if I set a named cell to a certain value, using an offset from that cell it will then hide the specified number of rows (see code here)
So in above example, setting the named cell "Contract_Value" to "Do Not Tick" will result in the next 20 rows below it being hidden. So far, so good.
However, within those 20 rows, I have options that also need to be hidden e.g. if I set my named cell "Contract_Value" to "Tick" instead of "Do Not Tick", it will leave those 20 rows unhidden. Then, within those 20 rows, I may have another named cell (let's say in row 7 for argument's sake) that if set "Do Not Tick" should then hide the next 2 rows (using same offset code as above). The problem is that if I write the code for that named cell, when I use the first piece of code above, then rows I have specified to hide depending on the value in the named cell on row 7 do not hide.
So, by way of example, "Group_Accounts_Value" is a named cell that is contained within the 20 row offset from the named cell "Contract_Value", row 8 to be precise. If I set "Contract_Value" to "Do Not Tick", it hides all the 20 rows underneath it with the exception of row 9, which is the row that would be hidden if I didn't set the "Contract_Value" named cell to "Do Not Tick" and just set the "Group_Accounts_Value" named cell to "Do Not Tick".
All suggestions greatly appreciated. While it's not crucial I get this working properly, it sure would be nice to!
VBA Code:
If Range("Contract_Value").Value = "Do Not Tick" Then
Range("Contract_Value").Offset(1).Resize(20).EntireRow.Hidden = True
Else
Range("Contract_Value").Offset(1).Resize(20).EntireRow.Hidden = False
End If
However, within those 20 rows, I have options that also need to be hidden e.g. if I set my named cell "Contract_Value" to "Tick" instead of "Do Not Tick", it will leave those 20 rows unhidden. Then, within those 20 rows, I may have another named cell (let's say in row 7 for argument's sake) that if set "Do Not Tick" should then hide the next 2 rows (using same offset code as above). The problem is that if I write the code for that named cell, when I use the first piece of code above, then rows I have specified to hide depending on the value in the named cell on row 7 do not hide.
Code:
If Range("Contract_Value").Value = "Do Not Tick" Then
Range("Contract_Value").Offset(1).Resize(20).EntireRow.Hidden = True
Else
Range("Contract_Value").Offset(1).Resize(20).EntireRow.Hidden = False
End If
If Range("Group_Accounts_Value").Value = "Do Not Tick" Then
Range("Group_Accounts_Value").Offset(1).Resize(1).EntireRow.Hidden = True
Else
Range("Group_Accounts_Value").Offset(1).Resize(1).EntireRow.Hidden = False
End If
All suggestions greatly appreciated. While it's not crucial I get this working properly, it sure would be nice to!