【发布时间】:2020-04-21 04:30:24
【问题描述】:
我想在一个列表框中显示 2 个组合框的结果,但我不知道该怎么做...
这是我到目前为止所得到的:
1/ 我想显示软件包版本 ($E) 和软件包版本 ($F) 软件包名称selected 在左侧组合框选中项目的右侧组合框上(本例中为“监控”)。
2/ 如果我选择“ALL”包名,我想显示$E和$F。
这是我当前的代码:
Private Sub CommanButton1_Click()
Unload UserForm1
End Sub
Private Sub UserForm_Initialize()
Dim ws As Worksheet, rCell As Range, Key
Dim Dic As Object: Set Dic = CreateObject("Scripting.Dictionary")
Set ws = Worksheets("system-packages-installed")
UserForm1.ComboBox1.Clear
For Each rCell In ws.Range("B2", ws.Cells(Rows.Count, "B").End(xlUp))
If Not Dic.exists(LCase(rCell.Value)) Then
Dic.Add LCase(rCell.Value), Nothing
End If
Next rCell
UserForm1.ComboBox1.AddItem "ALL"
For Each Key In Dic
UserForm1.ComboBox1.AddItem Key
Next
End Sub
Private Sub ComboBox1_Click()
Dim rCell As Range, Key
Dim Dic As Object: Set Dic = CreateObject("Scripting.Dictionary")
Set ws = Worksheets("system-packages-installed")
UserForm1.ComboBox2.Clear
For Each rCell In ws.Range("B2", ws.Cells(Rows.Count, "B").End(xlUp))
If rCell.Value = ComboBox1.Value Then
If Not Dic.exists(LCase(rCell.Offset(, 1).Value)) Then
Dic.Add LCase(rCell.Offset(, 1).Value), Nothing
End If
End If
Next rCell
UserForm1.ComboBox2.AddItem "ALL"
For Each Key In Dic
UserForm1.ComboBox2.AddItem Key
Next
End Sub
Private Sub ComboBox2_Click()
'This is a test'
With UserForm1.ListBox1
.ColumnCount = 27
.ColumnWidths = "50"
.RowSource = "'system-packages-installed'!E:E"
End With
End Sub
如果您有任何问题,请随时问我。
提前致谢。
编辑:
这是表格:
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}
</style>
<table class="tg">
<tr>
<th class="tg-0pky">System_id<br></th>
<th class="tg-0pky">Machine</th>
<th class="tg-0pky">package_name</th>
<th class="tg-0pky">package_epoch</th>
<th class="tg-0pky">package_version</th>
<th class="tg-0pky">package_release</th>
</tr>
<tr>
<td class="tg-0pky">1000010000</td>
<td class="tg-0pky">monitoring</td>
<td class="tg-0pky">acl</td>
<td class="tg-0pky"></td>
<td class="tg-0pky">2.2.51</td>
<td class="tg-0pky">14.el7</td>
</tr>
<tr>
<td class="tg-0pky">1000010000</td>
<td class="tg-0pky">monitoring</td>
<td class="tg-0pky">alsa-lib</td>
<td class="tg-0pky"></td>
<td class="tg-0pky">1.1.6</td>
<td class="tg-0pky">2.el7</td>
</tr>
<tr>
<td class="tg-0pky">1000010000</td>
<td class="tg-0pky">monitoring</td>
<td class="tg-0pky">apg</td>
<td class="tg-0pky"></td>
<td class="tg-0pky">2.3.0b</td>
<td class="tg-0pky">24.el7</td>
</tr>
<tr>
<td class="tg-0pky">1000010000</td>
<td class="tg-0pky">monitoring</td>
<td class="tg-0pky">apr</td>
<td class="tg-0pky"></td>
<td class="tg-0pky">1.4.8</td>
<td class="tg-0pky">3.el7_4.1</td>
</tr>
<tr>
<td class="tg-0pky">1000010000</td>
<td class="tg-0pky">monitoring</td>
<td class="tg-0pky">apr-util</td>
<td class="tg-0pky"></td>
<td class="tg-0pky">1.5.2</td>
<td class="tg-0pky">6.el7</td>
</tr>
<tr>
<td class="tg-0pky">1000010000</td>
<td class="tg-0pky">monitoring</td>
<td class="tg-0pky">at</td>
<td class="tg-0pky"></td>
<td class="tg-0pky">3.1.13</td>
<td class="tg-0pky">24.el7</td>
</tr>
<tr>
<td class="tg-0pky">1000010000</td>
<td class="tg-0pky">monitoring</td>
<td class="tg-0pky">audit</td>
<td class="tg-0pky"></td>
<td class="tg-0pky">2.8.4</td>
<td class="tg-0pky">4.el7</td>
</tr>
</table>
【问题讨论】:
-
请不要将数据添加为图像,将它们添加为文本。你可以用谷歌搜索“markdown table”并从中制作一个表格。
-
另外,您当前的代码有什么问题?
-
我真的不明白你为什么说“不要将数据添加为图像”......我当前的代码是正确的。但我真的不知道如何根据我的两个组合框显示值...
-
他是说您在 Excel 工作表中显示数据的图片。但是,如果有人想重现您的情况并测试他们的答案,他们必须输入(而不是复制和粘贴)所有这些数据。
标签: excel vba combobox listbox userform