You are on page 1of 4

hiding an entire row -conditional basis

Hi all,

Could anyone guide me how can I hide the row no 13 when I select "CLINKER" in E3 cell. I have
used this code but its giving error.

Code:

Private Sub Worksheet_Change(ByVal Target As Range)


If Target = Range("E3") Then
Select Case UCase(Target.Value)
Case "CLINKER"
Range("13").EntireRow.Hidden = True
Case "CEMENT"
Range("13").EntireRow.Hidden = False
End Select
End If
End Sub

A case of using range instead of rows cammand

try this

Code:

Private Sub Worksheet_Change(ByVal Target As Range)


If Target = Range("E3") Then
Select Case UCase(Target.Value)
Case "CLINKER"
Rows("13").EntireRow.Hidden = True
Case "CEMENT"
Rows("13").EntireRow.Hidden = False
End Select
End If
End Sub

The error message means that you have two macros with the same name.

In addition, you can only have one worksheet_change.

Loks like you probably need to add another Case to the existing code. In any case you must
amend the existing code.

Code:

Private Sub Worksheet_Change(ByVal Target As Range)


If Target = Range("E3") Then
Select Case UCase(Target.Value)
Case "CLINKER"
Rows("13").EntireRow.Hidden = True
Case "CEMENT"
Rows("13").EntireRow.Hidden = False
case "HARDCORE"' or whatever
Rows("13").EntireRow.Hidden = False
End Select
End If

End Sub

Thanks roy. Could you please tell me how can I change the name of the 2nd macro. Thanks for
your code but its not giving my expected output. (In 2nd case)I need to hide the row with different
condition & in different cell (not in the E3). I want to use F2 cell as an input in the 2nd case so if
F2="hardcore" then hide the row no. 50 & F2='softcore" then unhide this row.

could you please gide me so that I can use both the cases separately.

ss_bb_24

If you change the name of one of the macros it will no longer work when the worksheet is
changed.

You also can not have more than 1 macro on the module with the same name

Which means that you need 1 macro that handles both conditions

Code:

Private Sub Worksheet_Change(ByVal Target As Range)


If Target = Range("E3") Then
Select Case UCase(Target.Value)
Case "CLINKER"
Rows("13").EntireRow.Hidden = True
Case "CEMENT"
Rows("13").EntireRow.Hidden = False
Case "HARDCORE" ' or whatever
Rows("13").EntireRow.Hidden = False
End Select
ElseIf Target = Range("f2") Then
Select Case LCase(Target.Value)
Case "hardcore"
Rows("50").EntireRow.Hidden = True
Case "'softcore"
Rows("50").EntireRow.Hidden = False
End Select
End If
Thanks a lot. I have used the below code & 1st case is working but 2nd case is not working.
Code:

Private Sub Worksheet_Change(ByVal Target As Range)


If Target = Range("BA82") Then
Select Case UCase(Target.Value)
Case "IN DETAILS"
Rows("83").EntireRow.Hidden = True
Case "SIMPLE"
Rows("83").EntireRow.Hidden = False
End Select

ElseIf Target = Range("BA4") Then


Select Case LCase(Target.Value)
Case "CLINKER"
Rows("54").EntireRow.Hidden = True
Case "'CEMENT"
Rows("54").EntireRow.Hidden = False
End Select
End If
End Sub

The line
Code:

If Target = Range("BA82")

gave me an type mismatch error when Target was more than one cell.

Code:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


Application.ScreenUpdating = False

If Target.Address = "$BA$82" Then


With Rows(83)
.Hidden = (Not (LCase(Target.Value) = "in details"))
Imp .Hidden: Rem hide the row
.Hidden = Not ((.Hidden) Imp (LCase(Target.Value) = "simple")):
Rem show the row
End With
ElseIf Target.Address = "$BA$4" Then
With Rows(54)
.Hidden = (Not (LCase(Target.Value) = "clinker")) Imp .Hidden:
Rem hide the row
.Hidden = Not ((.Hidden) Imp (LCase(Target.Value) = "'cement")):
Rem show the row
End With
End If
Application.ScreenUpdating = True
End Sub

__________________

You might also like