Hide/Unhide rows based on value with a checkbox

Miltoft

New Member
Joined
May 26, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi everyone

I hope, that some of you are able to help me. I have a large excel sheet with a lot of rows. I column "F" I have the status stated. It can be open, closed or blank. I would like to have a checkbox that hides every row with the status of "Closed".

I have tried this, but that won't work.

Private Sub CheckBox1_Click()

If Range("F31:395").Value = "Closed" Then
[31:395].EntireRow.Hidden = True

Else: [31:395].EntireRow.Hidden = False

End If

End Sub

Best regards

Daniel
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Normally when using a checkbox

We would say something like:
If checkbox1.value=True then do this
If checkbox1.value=False do this

Like this:
VBA Code:
Private Sub CheckBox1_Click()
'Modified  2/9/2022  5:40:07 AM  EST
If CheckBox1.Value = True Then MsgBox "Yes"
If CheckBox1.Value = False Then MsgBox "No"
End Sub

Doing it the way you wrote your script it would be better to put the script in a Command Button.
 
Upvote 0
And you said:
If Range("F31:395").Value = "Closed" Then

So the script will only change things if all the values in the range are "Closed"

Or do mean if value in cell is closed do this this.
 
Upvote 0
And you said:
If Range("F31:395").Value = "Closed" Then

So the script will only change things if all the values in the range are "Closed"

Or do mean if value in cell is closed do this this.

First of all thank you very much for your help. Every row where column "F" contains the word "Closed" needs to be closed when the checkbox is true. And needs to be shown again when unchecking it.

Make sense?
 
Upvote 0
Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub


Fill in the "MSGBOX ".... with whatever line of code you want

Using to If statements limites you funtionality
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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