Excel 自动填写空白单元格中的月份
我有一个问题,如何改善我的宏去槽列A,当它找到空白单元格,然后它会在那个里键入月份的名称?我在下面尝试了类似的方法,但它只适用于Excel 自动填写空白单元格中的月份,excel,vba,Excel,Vba,我有一个问题,如何改善我的宏去槽列A,当它找到空白单元格,然后它会在那个里键入月份的名称?我在下面尝试了类似的方法,但它只适用于范围(“A1”).value而不是单元格(Rows.Count,“A”).End(xlUp)。Row Sub actual_month() 'fill month col Dim arrMonths() As String ReDim arrMonths(1 To 12) Application.DisplayAlerts = False arrMonths(1)
范围(“A1”).value
而不是单元格(Rows.Count,“A”).End(xlUp)。Row
Sub actual_month()
'fill month col
Dim arrMonths() As String
ReDim arrMonths(1 To 12)
Application.DisplayAlerts = False
arrMonths(1) = "JAN"
arrMonths(2) = "FEB"
arrMonths(3) = "MAR"
arrMonths(4) = "APR"
arrMonths(5) = "MAY"
arrMonths(6) = "JUNE"
arrMonths(7) = "JULY"
arrMonths(8) = "AUG"
arrMonths(9) = "SEP"
arrMonths(10) = "OCT"
arrMonths(11) = "NOV"
arrMonths(12) = "DEC"
Workbooks("UAC_report_p.xlsb").Activate
Sheets("SLA Calculation").Select
For Each Cell In ActiveSheet.UsedRange.Cells
'do some stuff
Next
For i = 1 To 12
Cells(Rows.Count, "A").End(xlUp).Row = Month(Date)
If Cells(Rows.Count, "A").End(xlUp).Row.Value = Month(Date) Then _
Cells(Rows.Count, "A").End(xlUp).Row.Value = arrMonths(Cells(Rows.Count, "A").End(xlUp).Row.Value)
Next i
Application.DisplayAlerts = True
End Sub
假设您使用的是当前月份,您可以这样做
Public Sub test()
Dim endrow As Long
Dim ws As Worksheet
Dim Col As Long
Dim arrMonths(1 To 12)
arrMonths(1) = "JAN"
arrMonths(2) = "FEB"
arrMonths(3) = "MAR"
arrMonths(4) = "APR"
arrMonths(5) = "MAY"
arrMonths(6) = "JUNE"
arrMonths(7) = "JULY"
arrMonths(8) = "AUG"
arrMonths(9) = "SEP"
arrMonths(10) = "OCT"
arrMonths(11) = "NOV"
arrMonths(12) = "DEC"
Set ws = Sheet4
'set column to "A"
Col = 1
endrow = ws.Cells(ws.Rows.Count, Col).End(xlUp).Row + 1
If ws.Cells(endrow, Col).Value = "" Then _
ws.Cells(endrow, Col).Value = arrMonths(Month(Now))
End Sub
编辑
更好的方法是根本不使用数组,而是使用LanguageID
获取特定语言中月份名称的等价物。有关LanguageID的完整列表,请参阅English\u United\u States
is409
试试这个代码
Public Sub test()
Dim ws As Worksheet
Dim Lrow As Long, Col As Long
Dim sMonth As String
Set ws = Sheet4
'~~> Not sure if Czech has same names as `Text` / `Today`.
'~~> If not then replace `Text` and `Today` with their respective equivalents.
sMonth = Application.Evaluate("=TEXT(TODAY(),""[$-409]MMM"")")
With ws
'~~> Set column to "A"
Col = 1
Lrow = .Cells(.Rows.Count, Col).End(xlUp).Row + 1
If .Cells(Lrow, Col).Value = "" Then _
.Cells(Lrow, Col).Value = sMonth
End With
End Sub
“当它的查找空白单元格时,它将在该单元格中键入月份名称?”。。。。。。那对我来说毫无意义。。您是指当前月份吗?当它找到空白单元格时,请输入哪个月份的名称?你怎么知道哪个月应该放在每个空白单元格中?这个月名,每个月运行一次,但他们希望自动运行。但问题是我来自捷克共和国,我想要11月11日的英文月名,如I=1到12,如I=1到12范围(“A20”)=月(日期)如范围(“A20”).Value=Month(Date)然后u0范围(“A20”).Value=arrmonents(Range(“A20”).Value)下一步我会工作,但仅在A20I将您的月份数组添加回那时。。。我认为您可以在Excel中更改区域设置,但绝对不会建议这样做。我真的非常感谢您的帮助,但这仍然不是我想要做的。我想在最后一次填写下的A栏填写NOVcell@SiddharthRout好小费。谢谢为了避免计算,您可以使用
Application.Text(现在为“[$-409]MMM”)