Excel/VBA简化到特定Excel单元格的导航

Excel/VBA简化到特定Excel单元格的导航,vba,excel,formula,Vba,Excel,Formula,我有几张Excel表格,每张都包含志愿者的信息卡(大约150个不同的名字)。我想创建一个只包含姓名的导航/摘要表,允许我直接跳转/转到位于同一文档中不同工作表上的特定志愿者姓名(特定单元格)。 在列表中选择一个名称或从摘要表上的下拉菜单中选择都是很好的选择 谢谢你给我的任何帮助 以下是我根据@strisel指令使用的代码: Sub ComboBox_Change() Dim Sheet1 As String Dim Sheet2 As String Dim A As St

我有几张Excel表格,每张都包含志愿者的信息卡(大约150个不同的名字)。我想创建一个只包含姓名的导航/摘要表,允许我直接跳转/转到位于同一文档中不同工作表上的特定志愿者姓名(特定单元格)。 在列表中选择一个名称或从摘要表上的下拉菜单中选择都是很好的选择

谢谢你给我的任何帮助

以下是我根据@strisel指令使用的代码:

Sub ComboBox_Change()
    Dim Sheet1 As String
    Dim Sheet2 As String
    Dim A As String
    Dim PickList As String

    listNamesSheet = "Name of your sheet where names are"
    secondSheet = "Name of your sheet, where the control is"
    colName = "Header of the column where names are"
    controlName = "Name of your combobox"

    With ThisWorkbook.Sheets(listNamesSheet)
        'Go through the range where names are
        For Each nameInSheet In .Range(colName & "1:" & colName & .Cells(.Rows.Count, colName).End(xlUp).Row)
            'If the name is the one selected in the ComboBox
            If (nameInSheet = ThisWorkbook.Sheets(secondSheet).DropDowns(controlName).List(ThisWorkbook.Sheets(secondSheet).DropDowns(controlName).Value)) Then
                'Activate the first sheet (have to if you want to select a range inside it)
                .Activate
                'Select the case where the name has been found
                .Range(nameInSheet.Address).Select
            End If
        Next nameInSheet
    End With
End Sub

Private Sub Workbook_Open()

    Dim Sheet1 As String
    Dim Sheet2 As String
    Dim A As String
    Dim PickList As String

    listNamesSheet = "Name of the sheet where names are"
    secondSheet = "Name of the sheet where you ComboBox is"
    colName = "Header of the column where names are" 'ex: "A" if names are in column A
    controlName = "Name of your combobox"


    With ThisWorkbook.Sheets(listNamesSheet)
        'Go through the range where all the names are
        For Each nameInSheet In .Range(colName & "1:" & colName & .Cells(.Rows.Count, colName).End(xlUp).Row)
            'Add it to the ComboBox
            ThisWorkbook.Sheets(secondSheet).DropDowns(controlName).AddItem nameInSheet
        Next nameInSheet
    End With
End Sub
在工作表中添加组合框 1。激活“开发人员”选项卡

进入文件选项自定义功能区>检查列表中的开发者

2。将组合框添加到工作表中

在开发者选项卡中,进入插入组合框

然后调整大小并按您的需要放置

3。更改组合框的名称

您可以通过选择组合框并在文本框(屏幕上的红色矩形)中更改其名称来更改组合框的名称

4。将宏指定给组合框

右键单击组合框并指定宏…

将出现一个窗口。选择函数的名称(屏幕上的左红色矩形),然后单击屏幕上显示的clicNew

现在可以插入代码,以便在组合框的值更改时执行

对于您,请在已创建的函数中插入以下代码

    Dim listNamesSheet As String
    Dim secondSheet As String
    Dim colName As String
    Dim controlName As String

    listNamesSheet = "Sheet1"
    secondSheet = "Sheet2"
    colName = "A"
    controlName = "PickList"

    With ThisWorkbook.Sheets(listNamesSheet)
        'Go through the range where names are
        For Each nameInSheet In .Range(colName & "1:" & colName & .Cells(.Rows.Count, colName).End(xlUp).Row)
            'If the name is the one selected in the ComboBox
            If (nameInSheet = ThisWorkbook.Sheets(secondSheet).DropDowns(controlName).List(ThisWorkbook.Sheets(secondSheet).DropDowns(controlName).Value)) Then
                'Activate the first sheet (have to if you want to select a range inside it)
                .Activate
                'Select the case where the name has been found
                .Range(nameInSheet.Address).Select
            End If
        Next nameInSheet
    End With

用你的名字填充你的组合框 1。添加工作簿_Open函数以在启动工作簿时加载您的姓名

回到您的代码中(Alt+F11或在开发者选项卡>查看代码中),在我们为组合框添加的代码之后添加以下函数

Private Sub Workbook_Open()

End Sub
这是一个在工作簿打开时触发的函数

2。填充您的组合框

将此代码添加到函数中

Dim listNamesSheet As String
Dim secondSheet As String
Dim controlName As String
Dim colName As String

listNamesSheet = "Sheet1"
secondSheet = "Sheet2"
colName = "A" 'ex: "A" if names are in column A
controlName = "PickList"


With ThisWorkbook.Sheets(listNamesSheet)
    'Clear before adding new names
    For i = ThisWorkbook.Sheets(secondSheet).DropDowns(controlName).ListCount To 1 Step -1
        ThisWorkbook.Sheets(secondSheet).DropDowns(controlName).RemoveItem i
    Next i

    'Go through the range where all the names are
    For Each nameInSheet In .Range(colName & "1:" & colName & .Cells(.Rows.Count, colName).End(xlUp).Row)
        'Add it to the ComboBox
        ThisWorkbook.Sheets(secondSheet).DropDowns(controlName).AddItem nameInSheet
    Next nameInSheet
End With

调整代码 在
listnamesheet=“Sheet1”
中更改第一张工作表的名称

secondSheet=“Sheet2”
中更改第二张图纸的名称

colName=“A”
中更改列的值

controlName=“PickList”
中更改组合框的名称


我没有解释太多关于代码的内容,因为它有注释,所以您必须能够理解,但不介意在注释中询问是否有不清楚的地方。

查看超链接-右键单击并手动在单元格中输入超链接,或者使用超链接公式:
=HYPERLINK([Book1.xlsx]Sheet2!A1”,“跳到Sheet2 A1。”)
这150张图纸上的名称是否始终在同一单元格中?然后你需要一个“for each sheet”-宏,这很容易做到。你好,Darren,不,150个名字分布在5张纸上,所以名字不在同一个单元格号中。但是这个公式非常好,但是需要我编辑公式以匹配正确的名称/正确的单元格。您好,这听起来像是我所寻找的动态,但它似乎没有低估说明,例如,如何创建下拉控件?您指的是VBA/插入模块吗?我是将其添加到包含志愿者信息的表格中,还是添加到摘要/第一张表格中?另外,如何添加DropDown1_Change()函数?我想我将不得不等待更多的细节,正如你所说。。。但是非常感谢already@Wiss别担心,我会用printscreen解释所有必要的内容。只要等几个小时,直到我回家:)@wis我做了一个相当完整的教程如何继续,让我知道如果一切都好。如果行得通的话,请接受我的回答。谢谢:)谢谢你的明确指示!由于某些原因,每当我尝试代码时,我都会遇到错误,我会遇到“脚本超出范围”错误或其他关于“只有在End Sub之后才需要注释。下面是我的代码的样子:@Wiss您能更详细地说明您遇到的错误吗?”?当出现错误时,“调试”按钮将显示出错的行。