Macro to hide row on Cell value and row value

lbanham

Board Regular
Joined
Feb 17, 2011
Messages
50
Hi

I am looking for a macro to hide any rows that contain "Month 2" in column D, and also if cell F1 contains "Month 2". This is in Sheet 1 of the workbook.
i would like it to hide/unhide automatically (when cell F1 is changed by data validation) rather than running the macro.

I am using Excel 2010.

Thanks

Lynsey
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long, i As Long
If Target.Address(False, False) = "F1" Then
    LR = Range("D" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        Rows(i).Hidden = Range("D" & i).Value = "Month 2"
    Next i
End If
End Sub
 
Upvote 0
Thanks for your reply - sorry for the delay in responding, Christmas Holidays etc.

Unfortunately this isnt working - I may not of explained it clearly.

I will try and explain it differently.
IF the value in cell G3 says "Costs" then all rows should be unhidden. If is says "Sales" in cell G3 any cell in column C with "Costs" in it, these rows should be hidden.

The rows to be hidden would be row 8 onwards.

Thanks again
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

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