Excel如何自動移至反白的儲存格

Excel如何自動移至反白的儲存格

我一直在擺弄甘特圖模板並編輯了一些內容。我注意到的缺點之一是當我更改單元格“E4”中的日期時。左側部分的儲存格將會反白顯示,但不會自動移動。

當我將日期更改為 2/2/2017 時。日期列將突出顯示,但我必須手動滾動到該日期。

問題:Excel有辦法自動將工作表移到選取的日期嗎?

甘特圖

答案1

您可以使用Worksheet_Change()事件來執行此操作。在裡面工作表如果您希望它繼續運行,請新增此程式碼。 (右鍵單擊工作表選項卡,然後轉到“查看代碼”):

Private Sub Worksheet_Change(ByVal Target As Range)
Dim dateCell As Range

If Target.Address = "$E$4" Then
    Set dateCell = Range("A49:A50").Find(what:=Target.Value)
    If dateCell Is Nothing Then
        MsgBox ("Date not found")
    Else
        dateCell.Select
    End If
End If
End Sub

注意:將 調整Set dateCell = Range([this range])為輸入日期後要「跳轉」的日期範圍。

相關內容