Hello,
I have this macro to hide columns based on the value of a cell but I would like to know how I could tweek it to make it hide 2 columns at a time ?
Thank you very much for your help !
Best regards,
Hippolyte
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rMin As Integer, rMax As Integer, i As Integer, ws As String
ws = "Feuille de calcul"
rMin = 10
rMax = 32
If Target.Address = "$H$10" Then
If Target.Value >= 1 And Target.Value <= 22 Then
rSave = rMin
Do
Worksheets(ws).Columns(rMin).EntireColumn.Hidden = False
rMin = rMin + 1
Loop While rMin <= rMax
rMin = rSave
i = Target.Value
rMin = rMin + i + 1
If rMin > rMax Then
rMin = rMax
End If
Do
Worksheets(ws).Columns(rMin).EntireColumn.Hidden = True
rMin = rMin + 1
Loop While rMin <= rMax
End If
End If
End Sub
I have this macro to hide columns based on the value of a cell but I would like to know how I could tweek it to make it hide 2 columns at a time ?
Thank you very much for your help !
Best regards,
Hippolyte
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rMin As Integer, rMax As Integer, i As Integer, ws As String
ws = "Feuille de calcul"
rMin = 10
rMax = 32
If Target.Address = "$H$10" Then
If Target.Value >= 1 And Target.Value <= 22 Then
rSave = rMin
Do
Worksheets(ws).Columns(rMin).EntireColumn.Hidden = False
rMin = rMin + 1
Loop While rMin <= rMax
rMin = rSave
i = Target.Value
rMin = rMin + i + 1
If rMin > rMax Then
rMin = rMax
End If
Do
Worksheets(ws).Columns(rMin).EntireColumn.Hidden = True
rMin = rMin + 1
Loop While rMin <= rMax
End If
End If
End Sub