代码之家  ›  专栏  ›  技术社区  ›  user7867367

VBA:如何使变量为空?

  •  7
  • user7867367  · 技术社区  · 7 年前

    我有以下变体:

    Dim comboitems() As Variant
    

    我在所有代码中使用的数组,它包含 ComboBox 控制

    在代码的某一点上,我需要清除/清空/null comboitems() . 我该怎么办?我尝试了以下所有选项,但都没有成功。

    comboitems = ""
    comboitems = Null
    comboitems = Nothing
    Set comboitems = ""
    Set comboitems = Null
    Set comboitems = Nothing
    comboitems() = ""
    comboitems() = Null
    comboitems() = Nothing
    Set comboitems() = ""
    Set comboitems() = Null
    Set comboitems() = Nothing
    

    我得到的错误是:

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  6
  •   John Ink    7 年前

    对于变量数组,可以使用erase命令清除它们。

    Erase comboitems
    

    下面是一个在vba中处理数组的简便参考指南:

    https://excelmacromastery.com/excel-vba-array/