从A列中的366天列表中查找/选择今天的日期

问题描述 投票:0回答:2

我在Excel中制作了一个日历表,其中一年中的所有366天都列在A列中如何编写自动选择并激活保存当前日期的单元格的Auto_open宏?

excel excel-vba
2个回答
0
投票
Private Sub Workbook_Open()

Dim lastrow As Long
Dim lastcol As Long
Dim t As Date
Dim u As Date
Dim v As Long
Dim w As Long
Dim notolet As String

Sheets("all").Activate ' your sheet name here
With ActiveSheet
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
End With

t = Now()
u = Format(t, "dd/mm/yyyy")
notolet = Split(Cells(1, lastcol).Address, "$")(1)

For v = lastrow To 2 Step -1
Select Case Cells(v, 1).Value
    Case u
       Range("A" & v & ":" & notolet & v).Interior.ColorIndex = 6
       Exit For
End Select
Next
w = v
End Sub

0
投票

尝试一下:

Private Sub Workbook_Open()
    Dim cell As Range
    Sheets("Sheet1").Activate
    Set cell = Range("A:A").Find(What:=Date, After:=Range("A1"))
    cell.Select
End Sub

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.