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
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)
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
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
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
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.