Hide and unhide rows based on cell value

Simmo1313

New Member
Joined
May 4, 2015
Messages
39
I have been trying to teach myself this through various forum threads but I have never used macros before so i'm not having any success.

I have a data range on sheet2 from A2:C16 and if any of the values in column C return a value of 0 I want to hide that row. If that value changes then I want to automatically unhide that row.

I want this macro to only have effect on sheet2 but I will more than likely want to use a similar hide macro on the other sheets within the same workbook but for different data ranges and other target columns. I'm hoping that I can use the same code but change the variables and insert it onto the other sheets?

If I could get a step by step process I would be extremely grateful as I am very much a novice.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Welcome to the Board!

Have you tried AutoFilter? If you filter column C and uncheck 0's then you can hide those rows.

How is the value in column C changing? If it's via formula then you can record a macro applying the filter, then call it from the worksheet Calculate event:

Code:
Private Sub Worksheet_Calculate()
  Call Filtercode
End Sub

HTH,
 
Upvote 0
Thanks Smitty,

Sometimes the simplest solution is the best, I was way over thinking that.

The value in C is changing by formula. So I'm not sure how to insert that macro to make the filter auto refresh?
 
Upvote 0
The Calculate event fires each time the sheet calculates, so you can use it to call your filtering code. Note that the Calculate code needs to go in the worksheet specific module.

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Calculate()<br>    <SPAN style="color:#00007F">Call</SPAN> FilterMe(3)<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> FilterMe(col <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>)<br>    Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN><br>        ActiveSheet.UsedRange.AutoFilter Field:=col, Criteria1:="<>0", Operator:=xlFilterValues<br>    Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>

This uses a variable to tell the filter which column to work on.
 
Upvote 0
I apologise for this but I have no idea how to input that macro or how to run it. This will be the first time I have used a macro for anything.

I have pressed alt+F11
right clicked the specific worksheet i want the macro to be active in and copy and pasted your code.
That's as far as I can get and it doesn't do anything so I'm sure i am missing steps.
The filter I want to update is in column C if that helps

Much appreciated
 
Upvote 0
The Calculate event code goes in the worksheet specific module. Then goto Insert-->Module and paste the FilterMe code there.

The code should fire when the worksheet calculates.

If you still have a problem, then PM me your e-mail address and I'll send you an example.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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