What does the keyword Set actually do in VBA?

Jon Artus picture Jon Artus · Dec 8, 2008 · Viewed 204.6k times · Source

Hopefully an easy question, but I'd quite like a technical answer to this!

What's the difference between:

i = 4

and

Set i = 4

in VBA? I know that the latter will throw an error, but I don't fully understand why.

Answer

Treb picture Treb · Dec 8, 2008

set is used to assign a reference to an object. The C equivalent would be

 int i;
int* ref_i;

i = 4; // Assigning a value (in VBA: i = 4)
ref_i = &i; //assigning a reference (in VBA: set ref_i = i)