# Hide Rows Based on Values of Two Different Cells

#### JeremyEBS

##### New Member
Hi all, I have been trying to find an answer to this question and can't seem to get my VBA code to work properly. I have two separate Active X check boxes controlling the TRUE/FALSE statement for two distinct cells. What I want the VBA code to do is to hide the row when both values controlled by the checkbox equal False. In simpler terms IF A52 = False & T52 = False, Then hide row 52. I would like this to be completed for rows 52-71 and rows 131-150. The location of the TRUE/FALSE statement remains in the same A and T column for each respective row. I hope this makes sense and any help is vastly appreciated!

### Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Code:
``````Dim i as long
For i = 52 to 71
If Range("A" & i)= False and Range("T" & i) = False then
Range("A" & i).entirerow.hidden= true
End if
Next i

for i = 131 to 150
If Range("A" & i)= False and Range("T" & i) = False then
Range("A" & i).entirerow.hidden= true
End if
Next i``````

This assumes that the True False are booleans and not strings. If strings, then they must be encased in quotation marks in the code.

Code:
``````Dim i as long
For i = 52 to 71
If Range("A" & i)= False and Range("T" & i) = False then
Range("A" & i).entirerow.hidden= true
End if
Next i

for i = 131 to 150
If Range("A" & i)= False and Range("T" & i) = False then
Range("A" & i).entirerow.hidden= true
End if
Next i``````

This assumes that the True False are booleans and not strings. If strings, then they must be encased in quotation marks in the code.

Great! I was able to make the code work! However, what would need to be added to the code in order to have the rows that were hidden to reappear if one of the cell values changes to True? would it be as simple as the same coding, but change true to false and false to true and command be entirerow.unhidden?

Great! I was able to make the code work! However, what would need to be added to the code in order to have the rows that were hidden to reappear if one of the cell values changes to True? would it be as simple as the same coding, but change true to false and false to true and command be entirerow.unhidden? (this doesn't exist, so what is the proper code to unhide?)

Code:
``Range("A" & i).entirerow.hidden= false``

But, if the row is hidden, you would have to unhide it first to make any changes. So you probably want to just use the same code to unhide all with the code above changing the status so that you can make changes to the data and then run the code again to hide.

Last edited:

Replies
11
Views
418
Replies
12
Views
621
Replies
16
Views
299
Replies
1
Views
573
Replies
1
Views
223

1,216,175
Messages
6,129,300
Members
449,499
Latest member
HockeyBoi

### 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.

### Which adblocker are you using?

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

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