得到下个月的名字

有没有人有任何的例子,我可以循环一个月在VBA转发?

目前我有一个月份值为“十月”的源表单。 我有一个embedded在工作表中的macrosbutton,创build一个新的工作表,我需要它从当前具有这个月价值单元格的值,并将其放置在新工作表,但一个月前,即在这个例子中的“十一月” 。

您可以创build一个可重用的函数,返回您正在查找的内容,也可以尝试使用Month / MonthName函数的组合来获得您正在查找的内容。

Function GetNextMonth(Byval currentMonth as string) As string Select Case currentMonth Case "January" GetNextMonth = "February" Case "February" GetNextMonth = "March" Case "March" GetNextMonth = "April" Case "April" GetNextMonth = "May" Case "May" GetNextMonth = "June" Case "June" GetNextMonth = "July" Case "July" GetNextMonth = "August" Case "August" GetNextMonth = "September" Case "September" GetNextMonth = "October" Case "October" GetNextMonth = "November" Case "November" GetNextMonth = "December" Case "December" GetNextMonth = "January" End Function 

更短的组合方法:

 Function GetNextMonth(ByVal currentMonth as string) As String GetNextMonth = MonthName(Month(DateValue("01-" & currentMonth & "-2000"))+1) End Function 

给VBA一个使用当前月份名称的date,让它转换它,然后从中获取月份号码,添加一个并返回月份名称。 但是,您可能需要添加检查以查看当前月份是否为12(边缘情况)。

作为用户定义的function

 Function NextMonth(m As String) As String NextMonth = Format(DateAdd("m", 1, DateValue("1 " & m & " 2000")), "mmmm") End Function 

或作为一个Excel公式(其中D1包含您要抵消的月份)

 =TEXT(EDATE( DATEVALUE("1 " & D1 & " 2000"),1), "mmmm")