我有一个带有四个数据验证下拉列表的工作表。我想用四个从属/级联组合框替换这四个数据验证下拉列表。我不想使用用户表单!
我在工作表中使用了一个组合框,我认为它只接受垂直列表。在该线程中,可能有一种解决方法:Excel VBA: Why does combo box shows only one item in the list?
我也希望我的组合框是依赖/级联的。在此线程中,VBA中可能有一个解决方案:How to list combo box data based on another combo box entry
此外,我正在使用四个数据验证下拉列表的单元格范围/地址来执行vlookup。如何在vlookup公式中引用一个/两个/三个/四个组合框?
我需要帮助:
从水平列表的前两个组合框中选择创建两个从属组合框。
在多个vlookups公式中引用四个组合框的四个值。假设我在组合框中选择了瑞典,我想在我的vlookup公式中使用瑞典的值。我不确定组合框的工作方式,我在打字时正在阅读它们。此网页是一个不错的开始:https://support.office.com/en-us/article/add-a-list-box-or-combo-box-to-a-worksheet-in-excel-579e1958-f7f6-41ae-ba0c-c83cc6e40878在此youtube视频中,索引公式用于查找组合框的值:https://www.youtube.com/watch?v=VXlKM3YaWag
对组合框的填充列表进行排序。该线程有助于对多个条件进行排序:Excel VBA Multi line sort by multiple criteria in Excel 2016
答案 0 :(得分:0)
按住 Ctrl + t 将列表范围转换为表格。此代码适用于ActiveX ComboBox或ListBox。 MsFormsListName是具有控件的工作表的名称。该表可以在工作簿中调用该子例程的任何位置。
Sub Test()
AddTableRowAsListColumn "Table2", "ComboBox1", "Sheet2", 1
AddTableRowAsListColumn "Table2", "ListBox1", "Sheet2", 1
End Sub
Sub AddTableRowAsListColumn(TableName As String, MsFormsListName As String, MsFormsListWorksheetName As String, RowIndex As Long)
Dim MsFormsList As OLEObject
On Error Resume Next
Set MsFormsList = Worksheets(MsFormsListWorksheetName).OLEObjects(MsFormsListName)
On Error GoTo 0
If MsFormsList Is Nothing Then
MsgBox MsFormsListName & " not found on " & MsFormsListWorksheetName
Exit Sub
End If
MsFormsList.Object.list = WorksheetFunction.Transpose(Range(TableName).Rows(RowIndex).Value)
End Sub
Sub AddTableColumnToList(TableName As String, MsFormsListName As String, MsFormsListWorksheetName As String, ColumnIndex As Long)
Dim MsFormsList As OLEObject
On Error Resume Next
Set MsFormsList = Worksheets(MsFormsListWorksheetName).OLEObjects(MsFormsListName)
On Error GoTo 0
If MsFormsList Is Nothing Then
MsgBox MsFormsListName & " not found on " & MsFormsListWorksheetName
Exit Sub
End If
MsFormsList.Object.list = Range(TableName).Columns(ColumnIndex).Value
End Sub