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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
i think the simplest way because of the way i have the values in A is to have a helper column :)
 
Upvote 0
I had the same issue with that code a while back, i found that rather than having A result in "" have a helper column that results in a 1 instead and

VBA Code:
If c.Value = 1 Then
 
Upvote 0
hmmmm nope, still hides every row.... frustrating.
 
Upvote 0
I had the same issue with that code a while back, i found that rather than having A result in "" have a helper column that results in a 1 instead and

VBA Code:
If c.Value = 1 Then
oh yeah i think because i left it in quotes!!.... let me try that
 
Upvote 0
h
I had the same issue with that code a while back, i found that rather than having A result in "" have a helper column that results in a 1 instead and

VBA Code:
If c.Value = 1 Then
mmm nope didnt work lol
 
Upvote 0
But have you changed the range Values to where the helper cells are and not column A?
 
Upvote 0
Lets say column F is the helper column

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

Dim c As Range
Rows("4:50").EntireRow.Hidden = False
        'rehide the blanks
            For Each c In Range("f4:f50")
                If c.Value = 1 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
 
Upvote 0
Lets say column F is the helper column

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

Dim c As Range
Rows("4:50").EntireRow.Hidden = False
        'rehide the blanks
            For Each c In Range("f4:f50")
                If c.Value = 1 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
i tried it like that.... still hides every row between 4 and 50. in column z is the helper. i have had to use a formula there though to know which is blank and not? so it says if(A5="",1,2)
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,755
Members
449,049
Latest member
excelknuckles

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