VBA添加mmm-yy和商业季度的date

我已经创build了一个VBA来自动填充date,当下拉列表被选中,但需要date格式为mmm-yy和业务季度被填充在下一个单元格。

这是我创build的,请帮助添加mmm-yy和业务季度。

 With Target If .Column <> 10 Or .Row < 1 Then Exit Sub If .Value = "Select" Then If .Offset(0, 1).Value = "" Then .Offset(0, 1).NumberFormat = "mm/dd/yy" .Offset(0, 1).Value = Now - 1 End If 

获得业务季度有点主观。 地区之间的财政年度发生变化。 下面的例子假设1月 – 3月= Q1,4月 – 6月= Q2等:

 Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) With Target If .Column <> 10 Or .Row < 1 Then Exit Sub If .Value = "Select" Then If .Offset(0, 1).Value = "" Then .Offset(0, 1).NumberFormat = "mm/dd/yy" .Offset(0, 1).Value = Now - 1 .Offset(0, 2).Value = Now - 1 .Offset(0, 2).NumberFormat = "mmm-yy" '<~~ mmm-yy .Offset(0, 3).Value = GetBusinessQuarter(.Offset(0, 1)) '<~~ business quarter End If End If End With End Sub Function GetBusinessQuarter(dt As Date) As String ' credit: https://exceljet.net/formula/get-fiscal-quarter-from-date GetBusinessQuarter = "Q" & CStr(Choose(Month(dt), 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)) End Function