Hello,
I am writing a macro to generate a pie chart from a growing database. I have written the below code to move all of the data entries from a specific month from the large database to another sheet to facilitate generating the chart.
My problem: In the userform I'm using to find and move the data I have a listbox offering the last 12 months as selections. In the loop function I built either I cannot get the value recognized as a date or the range of my selected date is botched.
Running the above code gives me a runtime error 13 as a "type mismatch"
I'm guessing it has to do with judging the value of the "A" column as a date, but I'm not really sure.
Any help would be greatly appreciated.
I am writing a macro to generate a pie chart from a growing database. I have written the below code to move all of the data entries from a specific month from the large database to another sheet to facilitate generating the chart.
My problem: In the userform I'm using to find and move the data I have a listbox offering the last 12 months as selections. In the loop function I built either I cannot get the value recognized as a date or the range of my selected date is botched.
PHP:
Private Sub UserForm_Initialize()
'lbmonth fill
With lbmonth
.AddItem Format(Date, "MMMM")
.AddItem Format(DateAdd("M", -1, Date), "MMMM")
.AddItem Format(DateAdd("M", -2, Date), "MMMM")
.AddItem Format(DateAdd("M", -3, Date), "MMMM")
.AddItem Format(DateAdd("M", -4, Date), "MMMM")
.AddItem Format(DateAdd("M", -5, Date), "MMMM")
.AddItem Format(DateAdd("M", -6, Date), "MMMM")
.AddItem Format(DateAdd("M", -7, Date), "MMMM")
.AddItem Format(DateAdd("M", -8, Date), "MMMM")
.AddItem Format(DateAdd("M", -9, Date), "MMMM")
.AddItem Format(DateAdd("M", -10, Date), "MMMM")
.AddItem Format(DateAdd("M", -11, Date), "MMMM")
End With
End Sub
Private Sub cbchartgenerator_Click()
Dim i, LastRow
LastRow = Sheets("Tracker").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Monthly Category").Range("A2:D500").ClearContents
For i = 2 To LastRow
If Sheets("Tracker").Cells(i, "A").Value = Range((DateSerial(Year(Me.lbmonth), Month(Me.lbmonth), 1)), (DateSerial(Year(Me.lbmonth), Month(Me.lbmonth) - 1, 0))) Then
Sheets("Tracker").Cells(i, "A").EntireRow.Copy Destination:=Sheets("Monthly Category").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
End Sub
Running the above code gives me a runtime error 13 as a "type mismatch"
I'm guessing it has to do with judging the value of the "A" column as a date, but I'm not really sure.
Any help would be greatly appreciated.