why is this code hiding all rows in range?

orsm6

Active Member
Joined
Oct 3, 2012
Messages
496
Office Version
  1. 365
Platform
  1. Windows
hi - when i step through this code i found it hides all the rows in column a4:a50 that have nothing in them (they contain formulas, but cell is blank) but when i call the code as part of another macro it hides every row in a4:a50 regardless if it has values.

every row in that range has a formula, but if a4:50 is blank then the rest of the columns are blank too.

Code:
Sub hiderows()
Worksheets("Layout").Activate

Dim c As Range
Rows("4:50").EntireRow.Hidden = False
        'rehide the blanks
            For Each c In Range("a4:a50")
                If c.Value = "" Then
                    c.EntireRow.Hidden = True
                Else
                    'do nothing, can resinstate the command below, but not required
                    c.EntireRow.Hidden = False
            End If
            Next
End Sub
 
Maybe this way
VBA Code:
Sub hiderows()
Worksheets("Layout").Activate
Dim c As Long
Rows("4:50").EntireRow.Hidden = False
For c = 4 To 50
    If Len(Range("A" & c)) = 0 Then Rows(c).EntireRow.Hidden = True
Next c
End Sub
Hi Michael - no unfortunately still hides all the rows.
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
In that case there not blank...what formula is in thos cells ?
 
Upvote 0
In that case there not blank...what formula is in thos cells ?
thats correct. my first post said that column A5:A50 has formulas. the formula is: =IFERROR(IF(D5=0,"",IF(ISNUMBER(SEARCH("WHEY LOSS",C5)),"Z002",INDEX(CK13a!$H$18:$H$100,MATCH(Layout!B5,CK13a!$L$18:$L$100,0)))),"")
 
Upvote 0
Yep, I understand that...if you put in an adjacent column =LEN(A4) and drag down what result do you get ?
Also, can you upload your worksheet / s to a hosting site, DropBox for instance, and someone will take a look at it.
 
Upvote 0
Yep, I understand that...if you put in an adjacent column =LEN(A4) and drag down what result do you get ?
Also, can you upload your worksheet / s to a hosting site, DropBox for instance, and someone will take a look at it.
i have a helper column (Z) if that helps? it contains 1 if the row is empty, 2 if it is not (a formula is used to get this)
no sorry i can't upload it as it contains sensitive ingredients and recipes relating to my workplace.
 
Upvote 0
i have a helper column (Z) if that helps? it contains 1 if the row is empty, 2 if it is not (a formula is used to get this)
no sorry i can't upload it as it contains sensitive ingredients and recipes relating to my workplace.
sorry to answer you question.... it returns the number 4 if the cell is 'blank' but 0 if it has a visible value
 
Upvote 0
So, if you are using the formula I provided and you get 4
it returns the number 4 if the cell is 'blank'
It is not a blank cell and therefore won't be hidden
 
Upvote 0
here is column A
IBR - New2.xlsm
A
4Material Type
5 
6Z004
7Z004
8Z004
9Z004
10Z004
11Z004
14Z003
15Z003
16Z003
Layout
Cell Formulas
RangeFormula
A14:A16,A5:A11A5=IFERROR(IF(D5=0,"",IF(ISNUMBER(SEARCH("WHEY LOSS",C5)),"Z002",INDEX(CK13a!$H$18:$H$100,MATCH(Layout!B5,CK13a!$L$18:$L$100,0)))),"")


here are the results in column Z
IBR - New2.xlsm
Z
4helper don’t delete
50
64
74
84
94
104
114
144
154
164
Layout
Cell Formulas
RangeFormula
Z14:Z16,Z5:Z11Z5=LEN(A5)
 
Upvote 0
So, if you are using the formula I provided and you get 4
it returns the number 4 if the cell is 'blank'
It is not a blank cell and therefore won't be hidden
correct not "blank" as i mentioned earlier.... but still need the rows hiddean that "appear" to be blank. that was why i tried a helper column to hide based on number, but it didn't work for me
 
Upvote 0
So if Z is the helper, Does this work for you
VBA Code:
Sub hiderows()
Worksheets("Layout").Activate
Dim c As Long
Rows("5:50").EntireRow.Hidden = False
For c = 5 To 50
    If Range("Z" & c) = 0 Then Rows(c).EntireRow.Hidden = True
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,052
Latest member
Fuddy_Duddy

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