Hide/Unhide Column based on Cell Value

xlingg

New Member
Joined
Jul 21, 2020
Messages
6
Platform
  1. Windows
Hi All,

I have been trying to look for a code to hide/unhide resignees on a click. I found a code but it only hide resignees but wouldn't show resignees upon clicking button again.

This is what I have:
VBA Code:
Public Sub HideResignee()
    Dim cell As Range, unionRng As Range
    For Each cell In ActiveSheet.Range("CX14:CX1013")
        If cell.Value = "Resignee" Then
            If Not unionRng Is Nothing Then
                Set unionRng = Union(unionRng, cell)
            Else
                Set unionRng = cell
            End If
        End If
    Next
    If Not unionRng Is Nothing Then unionRng.EntireRow.Hidden = True
End Sub

Appreciate any help! Thanks in advance!! :)
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try changing the last line to
Excel Formula:
If Not unionRng Is Nothing Then unionRng.EntireRow.Hidden = (unionRng.EntireRow.Hidden = False)
I haven't tried it with a non contiguous union range so not sure how well it will work with your code, especially if you change a new visible row to "Resignee" while the existing ones are hidden.
 
Upvote 0

Forum statistics

Threads
1,215,248
Messages
6,123,867
Members
449,130
Latest member
lolasmith

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