Hide Rows Based on Values of Two Different Cells

JeremyEBS

New Member
Joined
Sep 10, 2014
Messages
3
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!
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,864
Office Version
  1. 2019
Platform
  1. Windows
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.
 

JeremyEBS

New Member
Joined
Sep 10, 2014
Messages
3
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?
 

JeremyEBS

New Member
Joined
Sep 10, 2014
Messages
3
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?)
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,864
Office Version
  1. 2019
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,109,437
Messages
5,528,762
Members
409,834
Latest member
vexceled

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top