VBA - Filter Date by Month & Filter Name and Support location

Kenneth23

New Member
Joined
Nov 15, 2018
Messages
3
Hi,

I am new to VBA. I actually trying to learn on how vba work by trial and error.
In my worksheet, it involve with vba auto filter (support base and name) and vba advanced filter (month).
However, both auto filter and advanced filter cant run simultaneously on my data. What should i do in order for both of these filter. Is there any code they incorrect written
Attached is my worksheet which i working on.



Actually, i wanted to filter a range of people's birthday using month/ From example : if i input 11 in the entry cell, the filter result should be show the date fall on November.
In addition, i also want to filter their name and support location.

Code:
Option Explicit


Sub TableFilt()
Dim ContName, ContSupport As String
Dim LastRow As Long
With Sheet1
 LastRow = .Range("B99999").End(xlUp).Row
 If LastRow < 4 Then LastRow = 4
 If .Range("C3").Value = "Enter Name" Then ContName = Empty Else: ContName = .Range("C3").Value ' Name
If .Range("M3").Value = "Enter Support" Then ContSupport = Empty Else: ContSupport = .Range("M3").Value 'Support
    
 .Range("B4:N" & LastRow).Select
 Selection.AutoFilter
    With .Range("B4:N" & LastRow)
        If ContName <> Empty Then .AutoFilter Field:=2, Criteria1:="=*" & ContName & "*"
        If ContSupport <> Empty Then .AutoFilter Field:=12, Criteria1:="=*" & ContSupport & "*"
    End With
.Range("4:4").EntireRow.Hidden = False
End With
End Sub


Sub ClearFilt()
With Sheet1
.Range("A4").Value = True
.AutoFilterMode = False
.Range("C3").Value = "Enter Name"
.Range("H3").Value = "Enter Month"
.Range("M3").Value = "Enter Support"
.Range("A4").Value = False


End With
End Sub




Sub test()
    Dim temp
    With [h1:h2]
        temp = .Value
        .Cells(1).ClearContents
        .Cells(2).Formula = "=month(h5)=$h$3"
    End With
    With Range("h4", Range("h" & Rows.Count).End(xlUp))
        .AdvancedFilter 1, [h1:h2]
    End With
    [h1:h2].Value = temp
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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