Unfilter exceptions

nvdp2002

New Member
Joined
Nov 10, 2015
Messages
5
Dear excel boffins,

I have a macro that filters some rows out based on a cell being less than zero.
99% of the time, that's fine.
There is on occasion a reason to unhide 1 or 2 of the hidden ones. Ill explain in more detail below.

CompanyXXcode1-1
CompanyYYcode02
CompanyYYcode20
CompanyZZcode-11

<tbody>
</tbody>

The macro filters out row 3 at the moment because it filters out rows with 0 or less in them. What i would like to do instead is to take to total of columns 3 and 4 and filter on that.
The end result would be that if the total of columns 3 and 4 are more than 0 then it will not get filtered out.

Thanks in advance for help.

Kind Regards,
Nasser
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Use a "helper" column. Place a formula in that column, filter on that instead

So assuming above is columns A to D and that E is to contain helper formula...

manually Number Filter values in column E > 0 with this formula in E2 copied down
=C2+D2

VBA
Code:
rng.AutoFilter Field:=5, Criteria1:=">0"
 
Upvote 0
Hi Yongle,

Thanks for the tip. I wanted to do that as well, but the other filters refer to column numbers.
... Although after having said that i could just put the column right at the end.

Thanks for that. Talking things through clears them up nicely sometimes.

Do you know if there is another way to do with code? As in without the helper column. you idea is the easiest i think, just curious.

Kind Regards,
Nasser
 
Upvote 0
If all you want to do is to hide the rows, here is a way to do it without using data filter
- assumes first header is in A1 and data starts on row 2
- code hides all rows where columns C & D add up to zero or less

Code:
Sub HideRows()
    Dim arr, a, mystr As String
    With ActiveSheet
        arr = .Range("A1").CurrentRegion
        For a = 2 To UBound(arr)
            If arr(a, 3) + arr(a, 4) <= 0 Then
                If mystr = "" Then mystr = "A" & a Else mystr = mystr & ",A" & a
            End If
        Next a
        .Range(mystr).EntireRow.Hidden = True
    End With
End Sub

and to make visible again
Code:
Sub UnhideRows()
    ActiveSheet.Range("A1").CurrentRegion.EntireRow.Hidden = False
End Sub

The code
- copies the entire range into an array
- adds together the 3rd and 4th column in the array
- builds a comma delimited string of cell references for items that add up to 0 or less
- hides the rows containing those cells
 
Upvote 0

Forum statistics

Threads
1,214,970
Messages
6,122,514
Members
449,088
Latest member
RandomExceller01

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