Can a CDate be a month

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
This has a CDate function which needs to be a Month name is this possible?

VBA Code:
Private Sub Filter_Jobs_By_Months_Click()

Dim ws As Worksheet
Dim qt As QueryTable
Dim Mounths_List() As String
Dim IngStart As Long
Dim IngEnd As Long


Application.ScreenUpdating = False

Set ws = ThisWorkbook.Worksheets("TGS JOB RECORD")

For Each ws In ActiveWorkbook.Worksheets
For Each qt In ws.QueryTables
qt.Refresh
Next qt

IngStart = VBA.CDate(ws).Me.StartMonth
IngEnd = VBA.CDate(ws).Me.StartMonth
Application.ScreenUpdating = True
If IngStart > IngEnd Then
MsgBox "The Start Date Can Not be Bigger Then The End Date.", vbCritical, ""
Exit Sub
End If
ws.Range("A:A").AutoFilter Field:=11, _
Criteria1:=">=" & IngStart, Operator:=xlAnd, Criteria2:="<=" & IngEnd
With ws
.Range("K2").Value = Application.WorksheetFunction.Subtotal(2, .Range("A2:A" & .Rows(.Rows.Count).End(xlUp).Row))
End With

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
No, a month name is not a date. Also this:

Code:
VBA.CDate(ws).Me.StartMonth

makes no sense at all.
 
Upvote 0
Right, ok how would you overcome this?
Trying to filter data between months using Comboboxes
 
Upvote 0
You need to supply a day and year before CDate can work. It's not clear where those should come from.
 
Upvote 0
The thing is with this I don`t need the days for this just the months.
So what could I do instead of CDate to make it work?
 
Upvote 0
If the column you are filtering has actual dates in it, you need a date value to filter by. If it has month names, you’ll need a list of month names.
 
Upvote 0
I`ve created this code (Which works) but how could I get this to show in monthly order through a year.

VBA Code:
Private Sub UserForm_Initialize()
    Dim MyDate As Date
    Dim i As Integer
    MyDate = Date
    For i = 1 To 100
        Me.StartMonth.AddItem Format(MyDate, "mmmmm yy")
        Me.EndMonth.AddItem Format(MyDate, "mmmmm yy")
        MyDate = DateAdd("m", -1, MyDate)
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,842
Members
449,193
Latest member
MikeVol

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