Excel VBA 组合框清除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13130034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA Combo box clear
提问by Jiechao Li
I am using excel 2010.
我正在使用 excel 2010。
I want to clear the content of a combo box in my sheet(clear to blank like when it's not selected), but I don't know how to select and clear. I tried to select a combo box like this:
我想清除工作表中组合框的内容(就像未选中时一样清除为空白),但我不知道如何选择和清除。我尝试选择这样的组合框:
Sheet1.ComboBox1.Clear
But no 'ComboBox' is under the Sheet1 object. The only to select my combo box is use this:
但是 Sheet1 对象下没有“ComboBox”。唯一选择我的组合框是使用这个:
Sheet1.Shapes("Drop Down 24")
I don't know how to select and clear the content, can anyone help me?
我不知道如何选择和清除内容,有人可以帮助我吗?
采纳答案by lmb
What about
关于什么
ActiveSheet.Shapes.Range(Array("Drop Down 24")).Select
With Selection
.ListFillRange = ""
End With
回答by Daniel
I assume you actually want to make the displayed value of your control blank. In that case, for a Drop Down Object, as you indicated you would do this:
我假设您实际上希望将控件的显示值设为空白。在这种情况下,对于Drop Down Object,正如您所指出的那样,您将执行以下操作:
Sheet1.Shapes("Drop Down 2").OLEFormat.Object.Value = 0
Where 0 indicates which element from the list is selected I.E. none.
其中 0 表示选择了列表中的哪个元素 IE none。
If that doesn't work, then you're probably actually dealing with a ComboBox in which case you want to use this:
如果这不起作用,那么您实际上可能正在处理 ComboBox,在这种情况下您想使用它:
Sheet1.Shapes("Drop Down 2").OLEFormat.Object.Object.Value = ""
Note this code was created and tested in Excel 2003 (what I have on this machine) so the path to reaching the actual object might vary slightly on Excel 2010.)
请注意,此代码是在 Excel 2003(我在这台机器上拥有的)中创建和测试的,因此在 Excel 2010 上到达实际对象的路径可能略有不同。)
回答by Roger Barreto
As an autentic programmer I would rather prefer this way. That don't depends on excel "range memory selection" on the sheet.
作为一个真正的程序员,我更喜欢这种方式。这不取决于工作表上的excel“范围内存选择”。
Set oCombo = Sheets("SheetName").Shapes("cmbComboName").ControlFormat
For I = oCombo.ListCount To 1 Step -1
oCombo.RemoveItem (I)
Next
回答by Steve
To reset a Drop Down List to a blank cell but still maintaining the list for future use.
将下拉列表重置为空白单元格但仍保留列表以供将来使用。
Create a Macro to clear the cells. During recording simply select the cell and select "clear contents". This will set the selection to a blank cell but still keeps the drop down list in place.
创建一个宏来清除单元格。在录制过程中,只需选择单元格并选择“清除内容”。这会将选择设置为空白单元格,但仍保留下拉列表。
It would look like this for example.
例如,它看起来像这样。
Range("H3").Select
Selection.ClearContents