按月检查表

Sub IMPORT_MSG() Dim strMonth As String Dim strSheet As String strSheet = ActiveSheet.Name strMonth = Format(Date, ("mmmm" & "_yy")) If strSheet < strMonth Then MsgBox "test1" ElseIf strSheet >= strMonth Then MsgBox "test2" End if End sub 

我有12个月份的名字,比如(March_15,April_15)等等。 我已经做了这个代码来检查活动表是否在本月之前popupmessge1其他明智地显示message2。 问题是它不能正常工作。 我得到的结果如下:March_15给message2而不是message1 April_15给message1(正常)May_15,September_15,oktomber_15&November_15给message2(Normal)June_15,july_15,August_15&December_15给message1而不是message2

尝试这个

 Sub IMPORT_MSG() Dim Dt$, i&: i = 1 Dim Dic As Object: Set Dic = CreateObject("Scripting.Dictionary") Dic.CompareMode = vbTextCompare While i <= 12 Dic.Add MonthName(i), i: i = i + 1 Wend Dt = Left(ActiveSheet.Name, WorksheetFunction.Search("_", ActiveSheet.Name) - 1) If Dic(Dt) < Month(Date) Then MsgBox "test1" Else MsgBox "test2" End If End Sub