Excel 根据下拉菜单跳转到特定 column/cell

Excel jump to a specific column/cell based on a dropdown menu

我在一家疗养院做志愿者,为护理人员创造简单的解决方案,更好地帮助他们的居民。我正在开发一个交互式 Excel 日历,但我需要一个我一直在互联网上搜索但没有成功的功能。

我的 excel(VBA,我是根据类似问题猜测的)需要一个解决方案,允许用户从下拉列表中 select 日历日期很多日期,然后用户将跳转到该日期在另一个范围内的特定单元格。

我的日期范围在一行中:F9:UA9,我的下拉列表在 B11。

我希望通过 select 在下拉菜单中输入“20/09/2020”,用户将移至该日期首次出现的 F9:UA9 范围内的单元格。

这是一些示例数据。 [1]: https://i.stack.imgur.com/l4GjH.png

提前致谢!

您链接到的问题具有您需要的基本 shell。您可以使用 Application.Match 找到日期的第一个实例,然后 Application.Goto 滚动到它。

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim dropDownRange As Range
    Set dropDownRange = Me.Range("B11")

    '// Check if the change is happening in your dropdown cell
    If Not Intersect(Target, dropDownRange) Is Nothing Then
        Dim lookInRange As Range
        Set lookInRange = Me.Range("F9:UA9")

        Dim matchResult As Variant
        matchResult = Application.Match(CLng(dropDownRange.Value), lookInRange, 0)

        '// First check that the corresponding date was found
        If Not IsError(matchResult) Then
            Application.Goto lookInRange.Cells(matchResult), Scroll:=True
        End If
    End If
End Sub

sheet代码模块中添加这段代码

如果您想滚动到第 1 行,可能如下:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim dropDownRange As Range
    Set dropDownRange = Me.Range("B11")

    '// Check if the change is happening in your dropdown cell
    If Not Intersect(Target, dropDownRange) Is Nothing Then
        Dim lookInRange As Range
        Set lookInRange = Me.Range("F9:UA9")

        Dim matchResult As Variant
        matchResult = Application.Match(CLng(dropDownRange.Value), lookInRange, 0)

        '// First check that the corresponding date was found
        If Not IsError(matchResult) Then
            Dim matchRange As Range
            Set matchRange = lookInRange.Cells(matchResult)

            Application.Goto  Me.Cells(1, matchRange.Column), Scroll:=True
        End If
    End If
End Sub