Gingertrees
Well-known Member
- Joined
- Sep 21, 2009
- Messages
- 697
I have a command button that hides several ranges of rows when clicked, and I want to make this simpler to edit by defining the starts and ends of ranges using variables.
So my code now is:
WHERE I GET STUCK:
How do I tell the computer that the rows I want to hide are defined by variable? Here's some code-that-doesn't-work to show what I want:
How do I fix that annoying type mismatch error?!? I don't know any other way to define ranges of entire rows.
So my code now is:
Code:
Rows.("59:100").EntireRow.Hide = true 'range 1
Rows.("125:145").EntireRow.Hide = true 'range 2
'///ranges here are 25 rows apart
WHERE I GET STUCK:
How do I tell the computer that the rows I want to hide are defined by variable? Here's some code-that-doesn't-work to show what I want:
Code:
Private Sub CommandButton1_Click()
Dim Rg1Start As Long '1st row of 1st range
Rg1Start = 59
Dim Rg1end As Long 'last row in range 1
Rg1end = 100
Dim Distance1 As Long 'distance between range 1 and 2
Distance1 = 35 '///////////since I added some rows
Dim Rg2Start As Long
Rg2Start = Rg1end + Distance1 'beginning of range 2
Dim Rg2size As Long 'number of rows in range 2
Rg2size = 21
Dim Rg2End As Long
Rg2End = Rg2Start + Rg2size 'last row of range 2
With ActiveSheet.Rows("Rg1Start:Rg1end")
'!/!/!/!/runtime err 13 type mismatch/!/!/!/!/!/!
.EntireRow.Hide = True
End With
With ActiveSheet.Rows("Rg2Start:Rg2End")
.EntireRow.Hide = True
End With
End Sub