Question VBA - Filter by non fill cells background (only colored cells)

Raiyen

New Member
Joined
Feb 24, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I want to filter by non fill cells background (only colored cells) in VBA Code
Can someone share this tricks

Thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Welcome to the MrExcel board!

I want to filter by non fill cells background (only colored cells)
That is not entirely clear to me. If it is that you want to use AutoFilter to hide any cell that are coloured and just show the non-coloured cells, then starting with this sample

22 02 24.xlsm
A
1Header
2a
3b
4c
5d
6e
Sheet2 (2)


and applying this code

VBA Code:
Sub FilterNoColour()
  Range("A1:A7").AutoFilter Field:=1, Operator:=xlFilterNoFill
End Sub

produces this

22 02 24.xlsm
A
1Header
2a
4c
6e
Sheet2 (2)


If that is not what you want then perhaps you could explain again and give us your own 'before' and 'after' with XL2BB?
 
Upvote 0
Thanks Mr. peter for reply , but that's not what I want
in your screenshot I want to filter colored cells only (the green and blue color for example in the screenshot)

meaning the criteria is not equal to non fill color
 
Upvote 0
Then I think that you will need a helper column. Is that acceptable?
 
Upvote 0
See if you could use something like this then.
Here I want to filter the range A1:C6 by cells in column B being coloured.

22 02 24.xlsm
ABCD
1Hdr1Hdr2Hdr3
2Data 1aabc
3Data 2bdef
4Data 3c
5Data 4d
6Data 5emno
7
Filter Colour


VBA Code:
Sub FilterColour()
  Dim c As Range
  Dim b As Variant
  Dim i As Long
  
  With Range("A1:D" & Range("A" & Rows.Count).End(xlUp).Row)
    ReDim b(1 To .Rows.Count, 1 To 1)
    b(1, 1) = "Has Colour"
    For i = 2 To .Rows.Count
      If .Cells(i, 2).DisplayFormat.Interior.Color <> 16777215 Then b(i, 1) = "Y"
    Next i
    .Columns(.Columns.Count).Value = b
    .AutoFilter Field:=.Columns.Count, Criteria1:="Y"
  End With
End Sub

22 02 24.xlsm
ABCD
1Hdr1Hdr2Hdr3Has Colour
3Data 2bdefY
5Data 4dY
7
Filter Colour
 
Upvote 0
Thanks a lot Mr. Peter, you have my deepest gratitude :)
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,449
Members
448,966
Latest member
DannyC96

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