raven_squire
Board Regular
- Joined
- Jan 13, 2013
- Messages
- 99
Hello,
I taught myself to make macros in Excel VBA and I have some gaps in my knowledge. I recently looked at optomising some of my code and learnt that you can use a variant array to store varing data types in the same array. Previously I used a string array for both text and numeric values. As I understand it Variant is a data type where excel automatically manages the data type depending on how it evaluates the data.
Is there a way to force a variant to be treated in a certan way e.g. specify what data type that variant is? I want to use variants so that I can have an array of mixed data types. But I also want to avoid a situation where I get unexpected results because excel is treating the data as a different data type than what I was expecting.
I thought maybe I could do data type conversions to ensure the correct data type is used however this would also degrade performance. Many of my macros work on large data sets and take some time to complete as it is.
What is the best way to use variant types? Any help, tips or links to explanations would be apreciated.
I taught myself to make macros in Excel VBA and I have some gaps in my knowledge. I recently looked at optomising some of my code and learnt that you can use a variant array to store varing data types in the same array. Previously I used a string array for both text and numeric values. As I understand it Variant is a data type where excel automatically manages the data type depending on how it evaluates the data.
Is there a way to force a variant to be treated in a certan way e.g. specify what data type that variant is? I want to use variants so that I can have an array of mixed data types. But I also want to avoid a situation where I get unexpected results because excel is treating the data as a different data type than what I was expecting.
I thought maybe I could do data type conversions to ensure the correct data type is used however this would also degrade performance. Many of my macros work on large data sets and take some time to complete as it is.
What is the best way to use variant types? Any help, tips or links to explanations would be apreciated.