简体   繁体   English

更新下拉列表循环

[英]Updating drop down list loop

I'm trying to create a list which checks a database for the desired name and then adds that item to the drop down. 我正在尝试创建一个列表,该列表检查数据库的所需名称,然后将该项目添加到下拉列表中。 The code I have so far works as in it checks the name but then overwrites any previous entries in the list. 到目前为止,我拥有的代码可以检查名称,但随后会覆盖列表中的所有先前条目。 How can I alter so that it adds a new list item each time it finds the correct data? 我该如何更改,以便每次找到正确的数据时都添加一个新的列表项?

While ThisWorkbook.Worksheets("Inventory Database").Range("A" & j).Value <> ""
If ThisWorkbook.Worksheets("Inventory Database").Range("A" & j) = ThisWorkbook.Worksheets("Equipment Availability").Cells(1, i) Then
dvList = ThisWorkbook.Worksheets("Inventory Database").Range("B" & j)

'~~> Creates the list 
With Sheets("Equipment Availability").Cells(2, 2).Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:=dvList
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With
End If
j = j + 1
Wend    

You should only create the validation list once, while referencing a named range. 在引用命名范围时,您只应创建一次验证列表。 If you expand the named range on every loop (adding the new value), then the validation list will automatically be updated. 如果在每个循环上扩展命名范围(添加新值),则验证列表将自动更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM