VBA to hide rows

bakerman

Board Regular
Joined
Sep 9, 2005
Messages
188
I have been trying to find an old post that answers my question but i've had no luck.
What I want to do is hide or unhide a row based on the value in colloum D of the row that is being hidden or unhidden. I need this to look in rows D7 through to D46
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi

Try:

Code:
Sub test()
For Each c In Range("D7:D46")
    If c.Value Like "21*" Then 
           c.EntireRow.Hidden = True
    Else
           c.EntireRow.Hidden = False
    End If
Next c
End Sub

You need to amend your criteria (I currently have it that it looks at the (text) value in D and if it begins 21 then the rwo gets hidden). If you want it to check for a specifc value then you can use:

Code:
If c.Value = 3 ....    'for a numeric
If c.Value = "Roger" ....   'for a text value

Hope this helps

Richard
 

Forum statistics

Threads
1,176,538
Messages
5,903,655
Members
435,041
Latest member
Burleyg

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
Top