VBA: how to null a Variant?
Asked Answered
R

1

7

I have the following Variant:

Dim comboitems() As Variant

that I use in all the code as an array that contains the values of a ComboBox control.

In a certain point of the code, I need to clear/empty/null comboitems(). How can I do? I tried all of the following options without any success.

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

The error that I get is this:

enter image description here

Ratty answered 22/12, 2017 at 9:59 Comment(2)
Erase comboitems perhaps?Knawel
ReDim without preserve?Staple
H
6

For variant arrays, you'd clear them with the erase command.

Erase comboitems

Here's a handy reference guide for dealing with arrays in vba:

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

Hardly answered 22/12, 2017 at 10:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.