DDRA Steampunk
New Member
- Joined
- Feb 10, 2017
- Messages
- 23
I know I can combine more than one function on a button (as I have on each of these buttons), but I had no luck trying to combine the 2 buttons into 1. Seems like I should be able to do it with a "With" but I can't seem to make it work. I think it must have something to do with where I place the commands to hide and unhide the 2 sets of rows, but I just can't figure it out. I don't mind radical changes to how this button is coded or a completely different way of doing what I need to get done. I don't really understand how "calling" a macro or sub works so I haven't tried it. My VBA class textbook is like trying to read German when you've only learned French. I'm using Excel 2016. Suggestions appreciated
Code:
Public Sub ToggleButton1_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If ToggleButton1.Value = False Then
With ActiveSheet
BeginRow = 3
EndRow = 102
ChkCol = 18
For RowCnt = BeginRow To EndRow
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
Next RowCnt
End With
Else
With ActiveSheet
BeginRow = 3
EndRow = 102
ChkCol = 18
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value < 1 Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt
End With
With ActiveSheet
Dim x As Integer
For x = 1 To ActiveSheet.UsedRange.Columns.Count
Columns(x).EntireColumn.AutoFit
Next x
End With
End If
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Code:
Public Sub ToggleButton2_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If ToggleButton2.Value = False Then
With ActiveSheet
BeginRow = 124
EndRow = 142
ChkCol = 1
For RowCnt = BeginRow To EndRow
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
Next RowCnt
End With
Else
With ActiveSheet
BeginRow = 124
EndRow = 142
ChkCol = 1
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value < 1 Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt
End With
With ActiveSheet
Dim x As Integer
For x = 1 To ActiveSheet.UsedRange.Columns.Count
Columns(x).EntireColumn.AutoFit
Next x
End With
End If
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub