Hide/Unhide rows with CASE based on cell value with formula

jvandeliefvoort

New Member
Joined
Nov 10, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am quite new to VBA, and I cannot find an answer to my problem. I am using code to hide/unhide rows. It works when I put a value in cel B3, but this value must be a value on another sheet. So B3:
Excel Formula:
='Main Sheet 2.0'!H21
. So it only works if I put for example just the value 7 in B3, but not when I use the formula.

This is the code I used:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = ("$B$3") Then
        Select Case Target.Value
        Case "1"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:13").EntireRow.Hidden = False
        Case "2"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:22").EntireRow.Hidden = False
        Case "3"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:31").EntireRow.Hidden = False
        Case "4"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:40").EntireRow.Hidden = False
        Case "5"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:49").EntireRow.Hidden = False
        Case "6"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:58").EntireRow.Hidden = False
        Case "7"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:67").EntireRow.Hidden = False
        Case "8"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:76").EntireRow.Hidden = False
        Case "9"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:85").EntireRow.Hidden = False
        Case "10"
            Rows("7:94").EntireRow.Hidden = True
            Rows("7:94").EntireRow.Hidden = False
End Select
End If
End Sub

Thank you in advance!
 
:LOL: When I said "it" I was referring to using the formula approach.
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,616
Messages
6,125,862
Members
449,266
Latest member
davinroach

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top