Hiding Rows in a Range of Cells with If Statement

wrhoads88

New Member
Joined
Jun 16, 2012
Messages
1
Hello,

I would like to hide certain rows in a range of cells using an If statement. Here's the scenario...

In the Column "A", I would like to place a "*" in a cell to indicate that I would like that row to be hidden, then run a VBA code that says "if there's a "*" in that cell, hide that entire row.

I got this to work using 1 cell, but can't get it to happen with a range (i.e. all cells in Column A).

Code that worked with 1 cell:

Sub hide()
If Range("A4").Value = "*" Then
Range("A4").EntireRow.Hidden = True
Else
Range("A4").EntireRow.Hidden = False
End If
End Sub

This is what I've tried to get it to apply to a range, but can't figure it out:

Sub hide()
Dim star As Range
Set star = Range("A4:A7")

For Each Ccell In star
If Ccell.Value = "*" Then
EntireRow.Hidden = True
Else
EntireRow.Hidden = False
End If
Next
End Sub

Any help from the experts?? Thanks in advance!
William
 
EntireRow is a property, so it must have a cell/range object to which it applies...

Code:
Sub hide()
  Dim star As Range, Ccell As Range
  Set star = Range("A4:A7")
  For Each Ccell In star
    If Ccell.Value = "*" Then
      [B][COLOR=#FF0000]Ccell[/COLOR][/B].EntireRow.Hidden = True
    Else
      [COLOR=#FF0000][B]Ccell[/B][/COLOR].EntireRow.Hidden = False
    End If
  Next
End Sub
 
Upvote 0

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