Auto filter VBA

john Smith72

New Member
Joined
Apr 21, 2024
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hello,
Please I need your help

VBA to auto filter by colored cells in column (H) when I change months in cell C10 (Drop List)

I have used this macro but it didn't work automatically:


Private Sub Worksheet_activate()
'
' Reapply Autofilter Macro
'
ActiveSheet.AutoFilter.ApplyFilter
With ActiveWorkbook.Worksheets("2024").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

Thank You :)

EXAMPLE.xlsm
ABCDEFGHI
1No.IDNAMEDAYSFROMTILLCut ShortDAYS PER MONTH
21101SAMI1001/04/202410/04/20240
32102CAROL2002/04/202421/04/20240
43103HENRY4003/04/202412/05/202412
54104DANIEL9004/04/202402/07/202431
65105WILLIAM6005/04/202403/06/202402/05/20242
76106JOHN3001/04/202430/04/202430/04/20240
9
10MONTH5Months Drop List
2024
Cell Formulas
RangeFormula
A2:A7A2=SUBTOTAL(3,$C$2:C2)
F2:F7F2=IFERROR(DATE(YEAR(E2),MONTH(E2),DAY(E2)+D2-1),"-")
H2:H7H2=MAX(0,MIN(F2,IF(G2="",99999,G2),EOMONTH($C$10,0))-MAX(IF(COUNT(E2),E2,999999),$C$10)+1)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H2:H8Cell Value>0textNO
Cells with Data Validation
CellAllowCriteria
C10List=$B$12:$B$23
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
One way.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Me.Range("C10")) Is Nothing Then
        Me.Range("A1").CurrentRegion.AutoFilter Field:=8, Criteria1:=RGB(226, 239, 218), Operator:=xlFilterCellColor
    End If
End Sub
 
Upvote 1
Solution
One way.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Me.Range("C10")) Is Nothing Then
        Me.Range("A1").CurrentRegion.AutoFilter Field:=8, Criteria1:=RGB(226, 239, 218), Operator:=xlFilterCellColor
    End If
End Sub

Thank you very much rlv01 for your solution,
it worked perfectly,
your help is much appreciated. :)🌹
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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