I already asked this question, got few answers, but did not work exactly.
What I want is to hide-unhide some rows, depending from values in 3 different fields.
I want to change independantly these values.
For Example:
- I have 3 fields, num1, num2, num 3
- Depending from value in this field, 1,2,or 3, i will
hide unhide 3 ranges rows, for each
(If num1=1 unhide rng_01, hide rng_02, rng_03 )
(If num1=2 unhide rng_02, hide rng_01,rng_03 )
(If num1=3 unhide rng_03, hide rng_01,rng_02 )
(anything else hide rng_01,rng_02,rng_03 )
same thing for num=2,3 just different ranges:
num2-> 1.rng_11, 2.rng_12, 3.rng_13
num3-> 1.rng_21, 2.rng_22, 3.rng_23
My last VBA program was the following:
----------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Target.Address
Case Range("num1".Address
Call Num1Change
Case Range("num2".Address
Call Num2Change
Case Range("num3".Address
Call Num3Change
Case Else
Exit Sub
End Select
End Sub
---------------------------
Sub Num1Change()
'1 = unhide rng_01 and hide rng_02
'2 = unhide rng_02 and hide rng_01
'anything else, hide rng_01 and rng_02
cursht = ActiveSheet.Name
Sheets(cursht).Unprotect "123"
curcell = ActiveCell.Address
If num1 = 1 Then
Range("rng_01".Select
Selection.EntireRow.Hidden = False
Range("rng_02".Select
Selection.EntireRow.Hidden = True
ElseIf num1 = 2 Then
Range("rng_01".Select
Selection.EntireRow.Hidden = True
Range("rng_02".Select
Selection.EntireRow.Hidden = False
Else
Range("rng_01".Select
Selection.EntireRow.Hidden = True
Range("rng_02".Select
Selection.EntireRow.Hidden = True
End If
Application.Goto Range(curcell), True
Sheets(cursht).Protect "123"
Application.ScreenUpdating = True
End Sub
----------
Sub Num2Change()
--
--
End Sub
----------
Sub Num3Change()
--
--
End Sub
----------
Thos program does not hide and unhide those rows I want.
Does anybody have some comment why?
What I want is to hide-unhide some rows, depending from values in 3 different fields.
I want to change independantly these values.
For Example:
- I have 3 fields, num1, num2, num 3
- Depending from value in this field, 1,2,or 3, i will
hide unhide 3 ranges rows, for each
(If num1=1 unhide rng_01, hide rng_02, rng_03 )
(If num1=2 unhide rng_02, hide rng_01,rng_03 )
(If num1=3 unhide rng_03, hide rng_01,rng_02 )
(anything else hide rng_01,rng_02,rng_03 )
same thing for num=2,3 just different ranges:
num2-> 1.rng_11, 2.rng_12, 3.rng_13
num3-> 1.rng_21, 2.rng_22, 3.rng_23
My last VBA program was the following:
----------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Target.Address
Case Range("num1".Address
Call Num1Change
Case Range("num2".Address
Call Num2Change
Case Range("num3".Address
Call Num3Change
Case Else
Exit Sub
End Select
End Sub
---------------------------
Sub Num1Change()
'1 = unhide rng_01 and hide rng_02
'2 = unhide rng_02 and hide rng_01
'anything else, hide rng_01 and rng_02
cursht = ActiveSheet.Name
Sheets(cursht).Unprotect "123"
curcell = ActiveCell.Address
If num1 = 1 Then
Range("rng_01".Select
Selection.EntireRow.Hidden = False
Range("rng_02".Select
Selection.EntireRow.Hidden = True
ElseIf num1 = 2 Then
Range("rng_01".Select
Selection.EntireRow.Hidden = True
Range("rng_02".Select
Selection.EntireRow.Hidden = False
Else
Range("rng_01".Select
Selection.EntireRow.Hidden = True
Range("rng_02".Select
Selection.EntireRow.Hidden = True
End If
Application.Goto Range(curcell), True
Sheets(cursht).Protect "123"
Application.ScreenUpdating = True
End Sub
----------
Sub Num2Change()
--
--
End Sub
----------
Sub Num3Change()
--
--
End Sub
----------
Thos program does not hide and unhide those rows I want.
Does anybody have some comment why?