oceanorigami
New Member
- Joined
- Feb 28, 2014
- Messages
- 7
I want to run a filter "contains" RND on multiple columns but can't figure out how to do it. I think I need to use a macro or the Advanced Filter. Can anyone help explain how to do it?
OK, the columns are not really clear to me. From your sample data I have assumed you want to check from column C to the last column in your data and only display rows that have "RND" somewhere in those columns. If that is not what you want, please advise exactly which column letters need to be checked.I want to check the columns I tell it to check, Text1, Text2, Text3, etc. there are 20 columns like that
Sub Show_My_Rows_of_Interest()
Dim rCrit As Range
Dim sFormula As String, sRng As String
Const TextOfInterest As String = "RND"
Const FirstColOfInterest As String = "C"
Const fBase As String = "=COUNTIF(#,""*%*"")"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With ActiveSheet
On Error Resume Next
.ShowAllData
On Error GoTo 0
With .UsedRange
sRng = FirstColOfInterest & "2:" & .Cells(2, .Columns.Count).Address(0, 0)
Set rCrit = .Offset(, .Columns.Count).Resize(2, 1)
rCrit.Cells(2).Formula = Replace(Replace(fBase, "#", sRng, 1, -1, 1), "%", TextOfInterest, 1, -1, 1)
.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
End With
rCrit.ClearContents
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Sub Show_All_Rows()
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
End Sub
In G2 and copy to the right and down
=IF((COUNTA($G$1:G$1)=ROWS(G$2:G2))*(COUNTA($G$1:G$1)=COLUMNS($G2:G2)),"*"&$K$2&"*","")
If you are going to use Advanced Filter, as my macro does, then you must have a heading row. If you don't have a heading row, you need to put one in permanently or else the macro would need to put one in temporarily and remove it again at the end. If you need the macro to put in & take out a heading row, post back & I will make that adjustment.It worked! Thanks Peter_SSs One thing, I actually decided I don't even need the heading column so when I ran this macro it ends up keeping row 1 even without RND being in it. Can you make it include that?
OK, that's good. I think it makes sense to have headings anyway.It's fine how it is here, thanks a lot! ... You helped me a lot here thank you!
Spent too much time on this forum.How did you learn that it looks crazy hard!
@markmzz
For what it's worth, you can use a manual Advanced Filter with a formula in a single cell, rather than having to copy across and down and use a multi-cell criteria range.
For example, with your data as shown in columns A:E, and lookup text in K2, remove formulas and headings from columns G:I.
Put this formula in G2:
=COUNTIF(C2:E2,"*"&K$2&"*")
Now do your Advanced Filter with Criteria range G1:G2, noting that G1 is empty.
In G2
=COUNTIF(C2:E2,"*"&$I$2&"*")