Macro to Hide/Unhide Rows Based on Results in Column Equation

jwhite0720

New Member
Joined
Nov 4, 2011
Messages
6
<HR style="BACKGROUND-COLOR: #ebebeb; COLOR: #ebebeb" SIZE=1> <!-- / icon and title --><!-- message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_start --><!-- END TEMPLATE: ad_showthread_firstpost_start -->Hi there! I'm new to using these forums, but have spent some time scouring them from time to time to look for simple solutions to any excel/VBA problems I'm having. I consider myself relatively intermediate to advanced in Excel as far as formulas and spreadsheet creation goes, however VBA is foreign to me, and an area I'd love to learn. If any of you have recommendations on a good resource to begin learning VBA, please send it my way. And now....onto my macro question.

I've got a workbook with many tabs, and one or two input tabs feed information into another summary tab using various lookup and index formulas. There are any where from 40 to 80 rows to be qualified depending on the specific summary sheet (therefore I will likely need the macro to reference only the active sheet as it needs to work the same way on different sheets independent of each other). What I would like to do is if the result of the formula in column A of the summary sheet is "----------" (starts at A7) then I would like to hide that row, and if the data is changed on the input tab to result in anything other than the qualifying "----------", for that row to be unhidden. If this can be done dynamically that'd be great, however, if a button needs to be put into the spreadsheet to execute the macro, that will be fine too.

Thanks so much in advance for your help, and I promise I'll do my best to begin learning VBA so I can help contribute in return!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi and welcome.

This macro uses the Autofilter feature to hide all the rows on the active sheet where column A has "----------".

The second macro unhides all rows.

Code:
Sub Hide_Rows()
    ActiveSheet.Columns("A:A").AutoFilter Field:=1, Criteria1:="<>[COLOR="Red"]""----------""[/COLOR]", VisibleDropDown:=False
End Sub

Sub Show_All_Rows()
    ActiveSheet.AutoFilterMode = False
End Sub

Change the red part of the code to hide what you want. If you have literal quotes (as in your example) in the criteria, use two quotes for each literal quote.
 
Upvote 0
Thanks AlphaFrog.

This works great! Now I hope I can get some training in writing code so I can do other great things via macros in excel.
 
Upvote 0
Sorry about that Charles. Thanks for taking the time to respond, and I'm glad I got two variations of how to achieve the a similar result. I think this should help a bit with my understanding of writing code.
 
Upvote 0

Forum statistics

Threads
1,215,694
Messages
6,126,258
Members
449,307
Latest member
Andile

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