Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何在VBA中清除With块中的下拉列表?_Excel_With Statement_Vba - Fatal编程技术网

Excel 如何在VBA中清除With块中的下拉列表?

Excel 如何在VBA中清除With块中的下拉列表?,excel,with-statement,vba,Excel,With Statement,Vba,我有一个With块,它有一个条件来查看下拉列表中是否存在值 With wb.Sheets("BudgetLines").DropDowns("Drop Down 22") For Each c In refData.Range("G7:G" & LastRow_RefData).Cells Set Findo = wb.Sheets("BudgetLines").Cells.Find(c.Value, LookIn:=xlValues, _

我有一个With块,它有一个条件来查看下拉列表中是否存在值

   With wb.Sheets("BudgetLines").DropDowns("Drop Down 22")

    For Each c In refData.Range("G7:G" & LastRow_RefData).Cells

    Set Findo = wb.Sheets("BudgetLines").Cells.Find(c.Value, LookIn:=xlValues, _
                        SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
                        MatchCase:=False, SearchFormat:=False)






    If Findo Is Nothing Then
                Debug.Print "Name was not found."

                'DropDowns("Drop Down 22").Clear
            Else
               Debug.Print "Name found in :" & Findo.Address

                'Add title to drop down box
                .AddItem c.Value

            End If

    Next


End With
但是,我想完全清除下拉列表。我已经试过了。很清楚,但似乎不起作用,因为这是在With块中


有没有办法在With块中执行此操作?

您需要
RemoveAllItems
功能

Dim dd As DropDown
Set dd = wb.Sheets("BudgetLines").DropDowns("Drop Down 22")

With dd
    .RemoveAllItems
End With

看到这一点的诀窍是将变量
Dim dd声明为下拉列表
,当我

尝试时,它让我看到了
RemoveAllItems
函数。ClearContents?对于一个成员调用来说,没有太多指向
块。啊!谢谢,我想这可能很清楚或是什么@USE3535164请考虑将答案标记为有用(通过投票)并接受(点击投票按钮下方的灰色复选标记),如果它帮助您解决问题。你上面的评论表明情况就是这样。这有助于社区关注其他未回答的问题。