The following program will hide and unhide some rows depending from value in field "num" (Nice program from Dave W.)
Private Sub Worksheet_Change(ByVal num As Range)
'1 = unhide rng_1 and hide rng_2
'2 = hide rng_1 and unhide rng_2
'anything else, hide rng_1 and rng_2
If num.Address <> Range("num".Address Then Exit Sub
cursht = ActiveSheet.Name
Sheets(cursht).Unprotect "123"
curcell = ActiveCell.Address
If num = 1 Then
Range("rng_1".Select
Selection.EntireRow.Hidden = False
Range("rng_2".Select
Selection.EntireRow.Hidden = True
ElseIf num = 2 Then
Range("rng_1".Select
Selection.EntireRow.Hidden = True
Range("rng_2".Select
Selection.EntireRow.Hidden = False
ElseIf num > 2 Then
Range("rng_1".Select
Selection.EntireRow.Hidden = True
Range("rng_2".Select
Selection.EntireRow.Hidden = True
ElseIf num < 1 Then
Range("rng_1".Select
Selection.EntireRow.Hidden = True
Range("rng_2".Select
Selection.EntireRow.Hidden = True
ElseIf num = "" Then
Range("rng_1".Select
Selection.EntireRow.Hidden = True
Range("rng_2".Select
pplication.ScreenUpdating = True
End If
Application.Goto Range(curcell), True
Sheets(cursht).Protect "123"
Application.ScreenUpdating = True
End Sub
I have in same worksheet another variable field, called "typ". I want to hide and unhide some other rows depending from value in "typ", indipendently from "num"
Can I define in VBA Project this second condition for hiding-unhiding rows, and how to do it?
Private Sub Worksheet_Change(ByVal num As Range)
'1 = unhide rng_1 and hide rng_2
'2 = hide rng_1 and unhide rng_2
'anything else, hide rng_1 and rng_2
If num.Address <> Range("num".Address Then Exit Sub
cursht = ActiveSheet.Name
Sheets(cursht).Unprotect "123"
curcell = ActiveCell.Address
If num = 1 Then
Range("rng_1".Select
Selection.EntireRow.Hidden = False
Range("rng_2".Select
Selection.EntireRow.Hidden = True
ElseIf num = 2 Then
Range("rng_1".Select
Selection.EntireRow.Hidden = True
Range("rng_2".Select
Selection.EntireRow.Hidden = False
ElseIf num > 2 Then
Range("rng_1".Select
Selection.EntireRow.Hidden = True
Range("rng_2".Select
Selection.EntireRow.Hidden = True
ElseIf num < 1 Then
Range("rng_1".Select
Selection.EntireRow.Hidden = True
Range("rng_2".Select
Selection.EntireRow.Hidden = True
ElseIf num = "" Then
Range("rng_1".Select
Selection.EntireRow.Hidden = True
Range("rng_2".Select
pplication.ScreenUpdating = True
End If
Application.Goto Range(curcell), True
Sheets(cursht).Protect "123"
Application.ScreenUpdating = True
End Sub
I have in same worksheet another variable field, called "typ". I want to hide and unhide some other rows depending from value in "typ", indipendently from "num"
Can I define in VBA Project this second condition for hiding-unhiding rows, and how to do it?