Hide/Unhide Rows based on value in cell

onthegreen03

Board Regular
Joined
Jun 30, 2016
Messages
173
Office Version
  1. 365
Platform
  1. Windows
I know this question gets asked a lot, but I need some help with what I think is simple VBA coding. I have data in column C (rows 8 - 53). Via formula, some of the rows have data and some are blank (""). I need a macro that when run will hide all rows in cells C8:C53 that are blank, AND show all rows that have a value. I plan to create a button that when clicked will hide/unhide those rows based on the current cell value. Thanks for your help!
 
I know this question gets asked a lot, but I need some help with what I think is simple VBA coding. I have data in column C (rows 8 - 53). Via formula, some of the rows have data and some are blank (""). I need a macro that when run will hide all rows in cells C8:C53 that are blank, AND show all rows that have a value. I plan to create a button that when clicked will hide/unhide those rows based on the current cell value. Thanks for your help!
What not just use Filters to hide the rows based on their value?
 
Upvote 0
That is a good option (I always forget about that method). I was hoping to have a button at the top that the user can just click and the rows with values will show and the rows that are blank are hidden. If you think that is overkill/unnecessary I will go with the filter method.
 
Upvote 0
You can create a little VBA code to toggle the filter on and off, and link that code to your button, i.e.
VBA Code:
Sub ToggleRows()

    Dim myRange As Range
    
'   Set range to filter on
    Set myRange = Range("C7:C53")

'   If filter is on, shut it off,,,
    If ActiveSheet.AutoFilterMode Then
        myRange.AutoFilter
'   ...otherwise turn it on
    Else
        myRange.AutoFilter Field:=1, Criteria1:="<>"
    End If
    
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
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