Here is my data in the A column:
2013-SEP-04 10:51:42
2013-OCT-23 08:58:35
2013-OCT-23 08:58:35
2013-SEP-23 08:58:35
2013-OCT-23 08:58:35
2013-OCT-23 08:58:35
2013-SEP-23 08:58:35
Here is my code:
Sub getMonthNumber()
'
' getMonthNumber()
'
'
Dim rowsMonth As Long
Dim todaysMonth As Integer
Dim todaysMonthDate As Date
Dim column As Range, cell As Range
Set column = Range("A1:A" & ActiveSheet.UsedRange.Rows.Count)
inactiveStaffConnected = 0
todaysMonth = Month(Date) - 1
rowsMonth = 0
For Each cell In column
rowsMonth = Month(Mid(cell.Value, 10, 2) & Mid(cell.Value, 6, 3) & Mid(cell.Value, 1, 4))
Next
End Sub
1) Why the mismatch? The Month function works fine in this setup when using it straight in excel rather than a VBA script.
2) Is there a better way to parse the text into a date? The date string is too out of format with what excel considers a date which is why i'm issuing multiple mids.