Justplainj
Board Regular
- Joined
- Apr 15, 2021
- Messages
- 50
- Office Version
- 365
- Platform
- Windows
Good day All.
I am using the following code
I use it for a spin button to hide or unhide rows from row 77 to a max value entered by the user seen as "y" by the amount of rows "x"
When the value of x = 5 it will hide or unhide 5 rows, but if the value of x changes to 1, the first time you select the spin button 5 rows are hidden or unhidden and only after that initial 5 it then changes to 1.
Is it possible to amend the code to immediately only hide or unhide only 1 row instead of 5 on first click and then 1 on second onward?
I was thinking of added the x and y update to a seperate sub as a change event as per the below but that is not working.
Thank you
J
I am using the following code
VBA Code:
Private Sub SpinButton1_Change()
x = Sheet7.Range("P75")
y = Sheet7.Range("P76")
Sheet7.SpinButton1.SmallChange = x
Sheet7.SpinButton1.Max = y
If SpinButton1.Value = SpinButton1.Max Then ' this checks if the spinbutton is the last row or not. if it is it will exit the macro keeping all of the lines unhidden
Exit Sub
Else
Rows(SpinButton1.Value & ":" & SpinButton1.Max).Hidden = True
Rows(SpinButton1.Min & ":" & SpinButton1.Value).Hidden = False
Range("S" & SpinButton1.Value + 1 & ":" & "S" & SpinButton1.Max).ClearContents 'this clear the data validation of hidden cells so that when it is unhidden it shows nothing and a new selection can be made.
Range("P75").Select
End If
End Sub
I use it for a spin button to hide or unhide rows from row 77 to a max value entered by the user seen as "y" by the amount of rows "x"
When the value of x = 5 it will hide or unhide 5 rows, but if the value of x changes to 1, the first time you select the spin button 5 rows are hidden or unhidden and only after that initial 5 it then changes to 1.
Is it possible to amend the code to immediately only hide or unhide only 1 row instead of 5 on first click and then 1 on second onward?
I was thinking of added the x and y update to a seperate sub as a change event as per the below but that is not working.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
x = Sheet7.Range("P75")
y = Sheet7.Range("P76")
Sheet7.SpinButton1.SmallChange = x
Sheet7.SpinButton1.Max = y
End Sub
Thank you
J