Hide/Unhide Rows Based on Cell Value using VBA

hlhelterbrand

New Member
Joined
Dec 9, 2016
Messages
6
Hello,

So until now I have only viewed answers on this site, but it has helped me sooo many times! I could not find an answer to the question below, so hopeful one of you awesome people can help!

So I have few versions of what I have tried, but I think that a command button would work best. I am trying to use the name in column 2 to determine if the data in that row should be hidden or not. Ideally I would like the button to hide all lines that contain the name, then unhide all of those rows when clicked again.

Below is some code that I came up with, but it isn't working :(


Private Sub CommandButton1_Click()
BeginRow = 1
EndRow = 250
ChkCol = 2


If CommandButton1.Caption = "Hide Information" Then
ElseIf Cells(RowCnt, ChkCol).Value = "John Smith" Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
CommandButton1.Caption = "Show Information" And Cells(RowCnt, ChkCol).Value = "John Smith"
Else
Range("D:G, AF:AG, AJ:AO").EntireRow.Hidden = False
CommandButton1.Caption = "Hide Information"
End If
Next
End If
Next
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
use two buttons, that way you aren't trying to make a toggle
 
Upvote 0
I am trying to make the report user friendly. There are 18 different name buttons and I want each user to be able to select/ unselect their name. I have a master button that hides all, but it is not as natural. I have had two people test it out and they try to select the user button to hide/ unhide the information.
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

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