ChrisB
ChrisB

Reputation: 3205

How can I see the type of a variable in the MS Office VBA editor?

I no longer use Hungarian notation when coding VBA but I sometimes run into situations where the type of a given variable isn't obvious.

For example, take a variable with a name of dataRow. It could be a row number with a Long variable type. It could be a Range variable representing an entire row. It could be a ListRow in an Excel table. It could also be the Range of an Excel ListRow...and so on.

Is there some way to quickly look this up the the MS Office VBA editor? Can I somehow do this with variable naming without using variable names? I am not looking for opinions on the pros and cons of Hungarian notation, just how to see variable types without it.

Upvotes: 2

Views: 444

Answers (1)

barrowc
barrowc

Reputation: 10679

If you right-click on the variable name in question and select Quick Info, you will get a pop-up with the variable type. The pop-up also specifies if the variable is a local variable or an argument.

A screenshot from Excel's VBA editor. A Sub called foo is displayed which has a local variable called i which is an Integer. A yellow pop-up is displayed saying "Local i As Integer"

Variables from other scopes seem to just show the variable name and type. Constants don't indicate a variable type - they just give the constant name and value - e.g. "z = -1" but the value shown can be incorrect.

Upvotes: 4

Related Questions