Do While or For Loops?

Kaladin

New Member
Joined
Jul 16, 2014
Messages
48
I have a table that looks kind of like this:
T/FTrueFalseTrueTrueFalseFalseFalseTrue
A
B
C
D
E
F
G
H

<tbody>
</tbody>

The values in the blank spaces are either "N/A" or a number. I'm attempting to write something that will hide the row if all of the values under the columns marked "True" are "N/A" but will unhide the row if at least one of the values under a column marked "True" is a number.

I started out with a for loop going across the top to check for "True"s before going down the rows but it would just treat each column individually, instead of checking all "True" columns. Any tips about what I should be doing different are more than welcome.

If you're curious, this is for a dynamic chart to hide the irrelevant categories in an axis if they have no data.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You indicate you want to hide or unhide rows, but your description suggests you mean columns not rows. Please clarify. What cell is the first true/false header in?
 
Upvote 0
The first true/false header is C1. I do want to hide or unhide rows. The row is to be hidden if the cells under the "True" columns only have "N/A" in them. I'm sorry if I'm not explaining this well. English is hard.
 
Upvote 0
The first true/false header is C1. I do want to hide or unhide rows. The row is to be hidden if the cells under the "True" columns only have "N/A" in them. I'm sorry if I'm not explaining this well. English is hard.
What's in columns A & B? We need to know more about the layout of your data to help you. Can you post a sample of your data?
 
Upvote 0
The column A is empty. Column B has a list of company names. Sorry about the spacing, I don't know how to use the reply thing very well.

CheckboxTRUEFalseTrueTrueFalseFalseFalseTrueFalse
CompanyTwitter FollowersINS Twitter FollowersFacebook LikesLinkedIn FollowersINS LinkedIn FollowersGoogle+ FollowersINS Google+ FollowersYoutube SubsINS Youtube Subs
A80227N/A####N/A#N/A
B198551###N/A#N/A#N/A
C150925###N/A#N/A#N/A
D346957########
E1752020##N/A#N/A#N/A
F334049###N/A#N/A#N/A
G353325#####N/A#N/A

<tbody>
</tbody>
 
Last edited:
Upvote 0
The column A is empty. Column B has a list of company names. Sorry about the spacing, I don't know how to use the reply thing very well.

Checkbox
TRUEFalseTrueTrueFalseFalseFalseTrueFalse
CompanyTwitter FollowersINS Twitter FollowersFacebook LikesLinkedIn FollowersINS LinkedIn FollowersGoogle+ FollowersINS Google+ FollowersYoutube SubsINS Youtube Subs
A80227N/A####N/A#N/A
B198551###N/A#N/A#N/A
C150925###N/A#N/A#N/A
D346957########
E1752020##N/A#N/A#N/A
F334049###N/A#N/A#N/A
G353325###
##N/A#N/A

<tbody>
</tbody>
The True/false values are being returned to the first row by checkboxes? If any row below row 2 has an N/A in it you want to hide the row - is that correct?
 
Upvote 0
Yes, the true/false values are being returned by checkboxes.

I only want to hide a row if ALL the cells in that row with a corresponding TRUE in row 1 show "N/A".

So if row 50 has "N/A" under 3 of the 4 "TRUE" columns then it's not hidden because it only has "N/A" under 3 of the TRUE columns instead of 4. Is this making any sense?
 
Upvote 0
Yes, the true/false values are being returned by checkboxes.

I only want to hide a row if ALL the cells in that row with a corresponding TRUE in row 1 show "N/A".

So if row 50 has "N/A" under 3 of the 4 "TRUE" columns then it's not hidden because it only has "N/A" under 3 of the TRUE columns instead of 4. Is this making any sense?
Yes, it's making sense. I have to go offline now. If no one else has given you a solution when I return, I will try to provide one for you.
 
Upvote 0
The code below assumes the layout shown here. If I understand what you want correctly, only row 3 of the data below will be hidden after the code executes. Note that I'm using "N/A" as you posted for the criteria to hide. If you have formulas in your cells that are returning "#N/A" (w/o the quotes) you will have to change N/A to #N/A.
Excel Workbook
BCDEFGHIJK
1*TRUEFALSETRUETRUEFALSEFALSEFALSETRUEFALSE
2CompanyTwitter FollowersINS Twitter FollowersFacebook LikesLinkedIn FollowersINS LinkedIn FollowersGoogle+ FollowersINS Google+ FollowersYoutube SubsINS Youtube Subs
3AN/A65N/AN/A979797N/AN/A
4B198551100100100N/A100N/A100N/A
5C150925100100100N/A100N/A100N/A
6D346957100100100100100100100100
7E1752020100100N/A100N/A100N/A
8F334049100100100N/A100N/A100N/A
9G353325100100100100100N/A100N/A
Sheet5


Code:
Sub HideRowIfAllTrueNA()
Dim R As Range, c As Range, i As Long, Cols As Long, ct As Long
Set R = Range("B2").CurrentRegion
Cols = Application.CountIf(R.Rows(1), "True")
Application.ScreenUpdating = False
R.EntireRow.Hidden = False
For i = 3 To R.Rows.Count
    For Each c In R.Rows(i).Cells
        If c.Offset(-i + 1, 0) = "True" Then
            If c.Value = "N/A" Then
                ct = ct + 1
            Else
                Exit For
            End If
            If ct = Cols Then
                R.Rows(i).Hidden = True
                ct = 0
            End If
        End If
    Next c
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,807
Messages
6,121,679
Members
449,047
Latest member
notmrdurden

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