Vba 将月份名称转换为3个字母的缩写
有人知道如何把一个月的名字转换成3个字母的缩写吗?例如,如果月份是九月,那么它应该只返回九月。我一直在网上搜索,但不幸地得到了答案。谢谢 试试下面的方法Vba 将月份名称转换为3个字母的缩写,vba,excel,Vba,Excel,有人知道如何把一个月的名字转换成3个字母的缩写吗?例如,如果月份是九月,那么它应该只返回九月。我一直在网上搜索,但不幸地得到了答案。谢谢 试试下面的方法 Sub test() Dim a As String a = Format("11/10/2015", "MMM") MsgBox a End Sub 或 如果您将月份名称作为变量,那么 Sub test() Dim a As String a = "February" MsgBox Mid(a
Sub test()
Dim a As String
a = Format("11/10/2015", "MMM")
MsgBox a
End Sub
或
如果您将月份名称作为变量,那么
Sub test()
Dim a As String
a = "February"
MsgBox Mid(a, 1, 3)
End Sub
试试下面的
Sub test()
Dim a As String
a = Format("11/10/2015", "MMM")
MsgBox a
End Sub
或
如果您将月份名称作为变量,那么
Sub test()
Dim a As String
a = "February"
MsgBox Mid(a, 1, 3)
End Sub
始终起作用的是实现自己的功能,例如:
Function Month2Mon(month) As String
Select Case LCase(month)
Case "january": Month2Mon = "Jan"
Case "february": Month2Mon = "Feb"
...
End Function
始终起作用的是实现自己的功能,例如:
Function Month2Mon(month) As String
Select Case LCase(month)
Case "january": Month2Mon = "Jan"
Case "february": Month2Mon = "Feb"
...
End Function
您也可以尝试以下方法:
Sub Demo()
Dim MonthName As String
MonthName = "September"
MsgBox Format(DateValue("01 " & MonthName & " 2012"), "MMM")
End Sub
此解决方案源自@SiddhartRout的答案。您也可以尝试以下方法:
Sub Demo()
Dim MonthName As String
MonthName = "September"
MsgBox Format(DateValue("01 " & MonthName & " 2012"), "MMM")
End Sub
此解决方案源自@SiddhartRout的答案。如果我有一个等于月份名称的变量,该怎么办?@ramedju:
Mid(monthnamevaluate,1,3)
@shahkalpesh Mid的用途是什么?1和3?@ramedju:Mid
是一个函数,它接受字符串并提取其中的一部分。在本例中,从位置1中提取3个字符。如果我有一个等于月份名称的变量,该怎么办?@ramedju:Mid(monthnamevaluate,1,3)
@shahkalpesh Mid的用途是什么?1和3?@ramedju:Mid
是一个函数,它接受字符串并提取其中的一部分。在这种情况下,从位置1中提取3个字符太难了??什么意思?你想怎么做就怎么做。如果您喜欢,您可以更改月份
,以获得一个数字??什么意思?你想怎么做就怎么做。如果您愿意,您可以更改月份
,以获取一个数字