excel - 我正在尝试创建一个从单元格填充组合框选项的用户表单。我怎么能只从单元格范围中提取唯一值?
问题描述
这是我到目前为止将单元格中的所有值填充到我的组合框中的内容:
Private Sub UserForm_Initialize()
'Extracts Locations From Cells
Dim ws As Worksheet
Set ws = Worksheets("B")
Dim Location As Range
For Each Location In ws.Range("E7:E100")
With Me.Combobox
.AddItem Location.Value
End With
Next Location
End Sub
解决方案
我在另一个论坛上找到了答案。
https://www.mrexcel.com/board/threads/vba-multi-column-dictionary-key-into-combobox.863507/
Private Sub UserForm_Activate()
Application.ScreenUpdating = False
Dim rng As Range
Dim Dn As Range
Dim Dic As Object
Set rng = Range(Sheets("Subscription").Range("U2"), Sheets("Subscription").Range("U" & Rows.Count).End(xlUp))
Set Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
For Each Dn In rng
If Not Dn = vbNullString Then Dic(Dn.Value) = Empty
Next
With UserForm1.ComboBox1
.Columncount = 2
.RowSource = ""
.List = Dic.Keys
.ListIndex = 0
End With
推荐阅读
- python - Django Bootstrap Date Picker 默认值/todayBtn 问题
- c# - C# 使用 ClientCertificate 处理客户端请求
- c# - 如何为 Worker 服务安排任务
- r - 在不使用自由比例的情况下自定义 ggplots2 中的 y 轴
- powershell - NSIS 调用 powershell cmdlet Update-MpSignature 未被识别为 cmdlet powershell 的名称
- php - 页面重新加载后的 Invalid_grant Twinfield
- javascript - 来自 draw.io 的网络请求
- rabbitmq - spring.rabbitmq.listener.simple.retry.enabled=true 如果我手动配置 DirectMessageListenerContainer 将被忽略
- javascript - Array toString 中的参数有什么作用?
- html - 如何删除“粘性位置” div 背景?