'How to filter an excel column by Month name?
Given this list in excel:
How can I filter the rows (base on the date of birth column) when a user selects the name of the month? This is what I have done so far but I have no idea how to manipulate the DOB column:
Private Sub ComboBox2_Change()
On Error Resume Next
If Me.ComboBox2.Value = "<<All>>" Or Me.ComboBox2.Value = "" Then
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Else
Sheet1.Range("D4").AutoFilter field:=4, Criteria1:=Me.ComboBox2.Value
End If
End Sub
I don't have any idea what should I put on Criteria1.
Solution 1:[1]
First you sould in your code convert the month selected into a value (2 for february for example). Then you should probably extract the month from the DOB colmun by using a for loop like this (where selected month is the number of the corresponding month selected in the combobox):
Dim current_month
For i=4 To 13
current_month = Month(Range("D"&i).value)
If current_month <> selected_month Then 'The month don't correspond to the selected
Range("D"&i).EntireRow.Hidden = True 'Hide the row
next i
Let my know if it helps.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Baptiste ZLOCH |

