Okay so I'm trying to create a Show Hide button in excel, this is a big document so I don't want to create a new sub for each individual button with a new range for each one, I ideally want it to go off the button's location and I want to show/hide the 10 rows below the button. I've found a sub that joins both my 'Show' sub and my 'Hide' sub so I only have to use one button for this, but here is what I have so far:
Sub Hide()
Dim addr As Object, rs As Long, cs As Long
'addr is the address of the button
'rs is the row number
'cs is the column number
Dim offset1 As Long
'offset for rows value
Dim offset2 As Long
'offset 2 for row value
Dim rs1 As Long
Dim rs2 As Long
Dim rng As Range
Dim sheet As Worksheet
'rng is the cell the button is in
Set sheet = Worksheets("Sheet1")
Set addr = sheet.Shapes(Application.Caller)
'address of the shape using the macro (i.e. the button)
With addr.TopLeftCell
'coordinates of the top left cell of the button
rs = .Row
'row number
cs = .Column
'column number
End With
offset1 = -1
offset2 = -10
rs1 = rs + offset1
rs2 = rs + offset2
With sheet
.Cells(rs1 & ", " & cs).Select
Set rng = .Range(.Cells(rs1 & "," & cs), .Cells(rs2 & "," & cs))
End With
' let rng be the cell the button is in
rng.EntireRow.Hidden = True
End Sub
I had this working for my first button using the .offset and .resize functions but when I tried it in another location it didn't work without changing the offsets completely.
Thanks in advance