Share via

Excel Hide Rows When Value Entered

Anonymous
2017-08-03T06:18:01+00:00

I have to develop an excelsheet where a row is hidden automatically when the value is enter. There is 3 condition

An example like this:

Condition 1

If cell C16 = Value 1 to 3

Row 17 -> automatically hide row

Row 18 -> automatically hide row

Row 19 -> automatically unhide row

Condition 2

If cell C16 = Value 4 to 6

Row 17 -> automatically hide row

Row 18 -> automatically unhide row

Row 19 -> automatically hide row

Condition 3If cell C16 = Value 7 to 9

Row 17 -> automatically unhide row

Row 18 -> automatically hide row

Row 19 -> automatically hide row

etc.

Can you please help me?

Thanks a lot

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Vijay A. Verma 104.8K Reputation points Volunteer Moderator
    2017-08-03T10:52:00+00:00
    1. Make a backup of your workbook. 
    2. Open your workbook and ALT+F11
    3. Locate your Workbook name in Project Explorer Window
    4. Double click on your worksheet name
    5. Copy paste the Macro code given below
    6. Save your file as .xlsm
    7. If you want to add / change conditions change appropriately

    Private Sub Worksheet_Change(ByVal Target As Range)

        On Error GoTo ExitSub

        If Target <> Me.Range("C16") Or Target = "" Then Exit Sub

        Application.EnableEvents = False

        Select Case Target

            Case 1 To 3

                Rows("17:18").EntireRow.Hidden = True

                Rows(17).EntireRow.Hidden = True

                Rows(19).EntireRow.Hidden = False

            Case 4 To 6

                Rows(17).EntireRow.Hidden = True

                Rows(19).EntireRow.Hidden = True

                Rows(18).EntireRow.Hidden = False

            Case 7 To 9

                Rows("18:19").EntireRow.Hidden = True

                Rows(17).EntireRow.Hidden = False

            Case Else

                Rows("17:19").EntireRow.Hidden = False

        End Select

    ExitSub:

        Application.EnableEvents = True

    End Sub

    Was this answer helpful?

    0 comments No comments