VBA Code tp Hide row where a specific cell CONTAINS the result of a formula?

JMC57

Board Regular
Joined
Apr 24, 2012
Messages
118
I have the folowing formula in cells in col G

=IF(ISERROR(VLOOKUP(C4,$A$3:$B$596,2,FALSE)),"",VLOOKUP(C4,$A$3:$B$596,2,FALSE))

if there is no result then the cell is empty. I want to hide rows where cell G cotains a result . I know how to hide blank rows but can't seem to modify the code to do the opposite

I hope there is help out there! Thanks in advance
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try this:
Code:
Sub HideRowsWithContent()
Dim c As Range, R As Range
Set R = Intersect(ActiveSheet.UsedRange, Range("G:G"))
Application.ScreenUpdating = False
For Each c In R
    If c.Value <> "" Then c.EntireRow.Hidden = True
Next c
End Sub
 
Upvote 0
Thank you Joe Works great. What would need to be added to run from a command button toggle hide/unhide. I am sorry that I did not include this in my first request
 
Upvote 0
Joe I got the command button to work. I made a change in data that creates #REF! in what WAS the blank row. I tied to modify your code without success. Any help with this will be appreciated. Thank you very much
 
Upvote 0
Joe I got the command button to work. I made a change in data that creates #REF! in what WAS the blank row. I tied to modify your code without success. Any help with this will be appreciated. Thank you very much
I don't understand what you need help with. You want to hide a row if it contains an error like #REF or a value (non-blank)?
 
Upvote 0
I don't understand what you need help with. You want to hide a row if it contains an error like #REF or a value (non-blank)?

The rows that were blank now have #REF Therefore I need to NOT hide if if the result is #REF sicne that was fromally the blank row. Hide anything but REF or blank
 
Upvote 0
The rows that were blank now have #REF Therefore I need to NOT hide if if the result is #REF sicne that was fromally the blank row. Hide anything but REF or blank
Try this:
Code:
Sub HideRowsWithContent()
Dim c As Range, R As Range
Set R = Intersect(ActiveSheet.UsedRange, Range("G:G"))
Application.ScreenUpdating = False
For Each c In R
If Not IsError(c) Then
    If c.Value <> "" Then c.EntireRow.Hidden = True
End If
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,773
Messages
6,132,633
Members
449,740
Latest member
tinkdrummer

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