Apply filter on multiple columns

i have excel data colored in Red in column A in excel and i want to apply filter only on red color data and also Column B i want to apply filter where value is greater than 0

Out put should be

Data Amount
23 123
45 234
ty 7
[color data filter.xlsx attachment](upload://4S5JgfxvqwUKVQf7pHVSuJGxZtV.xlsx) (9.2 KB)
[color data filter.xlsx attachment](upload://4S5JgfxvqwUKVQf7pHVSuJGxZtV.xlsx) (9.2 KB)
[color data filter.xlsx attachment](upload://4S5JgfxvqwUKVQf7pHVSuJGxZtV.xlsx) (9.2 KB)

i have excel data colored in Red in column A in excel and i want to apply filter only on red color data and also Column B i want to apply filter where value is greater than 0
color data filter.xlsx (9.2 KB)

Hi @T_Y_Raju

Save the below vba as text file and use invoke vba activity

Sub FilterRedCells()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name

    ' Clear any existing filters
    If ws.AutoFilterMode Then ws.AutoFilterMode = False

    ' Apply filter to Column A for red colored cells
    ws.Range("A1").AutoFilter Field:=1, Criteria1:=RGB(255, 0, 0), Operator:=xlFilterCellColor
End Sub

Hope this helps :slight_smile:

For ref: https://youtu.be/nAckIftip0E?si=kEW9hpPJLX92UZ42

will this code filter data only with red font colored

Yes use this one.

Sub FilterRedCells()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name

    ' Clear any existing filters
    If ws.AutoFilterMode Then ws.AutoFilterMode = False

    ' Apply filter to Column A for red colored cells
    ws.Range("A1").AutoFilter Field:=1, Criteria1:=RGB(255, 0, 0), Operator:=xlFilterCellColor

    ' Apply filter to Column B for values greater than 0
    ws.Range("A1").AutoFilter Field:=2, Criteria1:=">0"
End Sub

1 Like

this macro is applying only filter on required column but filtering the data by color

Hi @T_Y_Raju

After doing what @AJ_Ask sent you, use Filter Activity present in Excel Activities and filter by your desired condition.

Thanks

Hi @T_Y_Raju ,

This thread will help you in applying a color based filter in column A.

You can use the Filter activity from excel package to set the value based filter in column B.

Thanks,
Gautham.

Hi @T_Y_Raju

To filter the ColumnA with color and Column B which is greater than 0. Then you have to use the Vb macros to filter the data.

You can use the below vb code,

Sub FilterData()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim colorFilterRange As Range
    Dim valueFilterRange As Range
    
    ' Set the worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
    
    ' Find the last row with data in column A and B
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    ' Set the ranges to filter
    Set colorFilterRange = ws.Range("A1:A" & lastRow)
    Set valueFilterRange = ws.Range("B1:B" & lastRow)
    
    ' Clear any existing filters
    If ws.AutoFilterMode Then
        ws.AutoFilterMode = False
    End If
    
    ' Apply filter based on the color in column A
    colorFilterRange.AutoFilter Field:=1, Criteria1:=RGB(255, 0, 0), Operator:=xlFilterCellColor
    
    ' Apply filter based on the value in column B
    valueFilterRange.AutoFilter Field:=2, Criteria1:=">0"
End Sub

Hope it helps!!

Hi @T_Y_Raju

You can use the Vb macros to apply the filter for ColumnA which is in red color and Column B which is greater than 0.

Sub FilterData()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim colorFilterRange As Range
    Dim valueFilterRange As Range
    
    ' Set the worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
    
    ' Find the last row with data in column A and B
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    ' Set the ranges to filter
    Set colorFilterRange = ws.Range("A1:A" & lastRow)
    Set valueFilterRange = ws.Range("B1:B" & lastRow)
    
    ' Clear any existing filters
    If ws.AutoFilterMode Then
        ws.AutoFilterMode = False
    End If
    
    ' Apply filter based on the color in column A
    colorFilterRange.AutoFilter Field:=1, Criteria1:=RGB(255, 0, 0), Operator:=xlFilterCellColor
    
    ' Apply filter based on the value in column B
    valueFilterRange.AutoFilter Field:=2, Criteria1:=">0"
End Sub

→ Store the above code in a .txt file.
→ Use the Invoke vba activity and give the path of the .txt file and give the FilterData as method name.

Hope it helps!!

Hi @T_Y_Raju ,

You can follow my blog for the same.