Why can't I use a string to reference an array in UBound?
For example, if I have an array called "Banks", UBound only works if I write the code this way
UBound(Banks)
It will not work if I have this:
String = "Banks"
UBound(String)
Is there any workaround this?
Perhaps it will help to be more specific with what I am trying to achieve.
I want to dynamically calculate the UBound of several arrays with as few lines of code as possible.
Given I have several banks to analyse, each of which contains several accounts, the idea would be to dynamically calc UBound for each by doing this:
'Banks
Dim Banks(1 To 5) As Variant
Banks(1) = "GS"
Banks(2) = "BAML"
...
Banks(5) = "Citi"
'Bank Accounts
Dim GS(1 to 15) As Variant
GS(1) = "Cash account"
GS(2) = "Repo account"
...
GS(15) = "Equities account"
Dim BAML(1 to 20) As Variant
BAML(1) = "Prime account"
BAML(2) = "Current account"
...
BAML(20) = "FX account"
Dim Banks_Total, Banks_Count as Integer
Dim Bank As String
Dim Account_Total as Integer
Banks_Total = UBound(Banks)
For Banks_Count = 1 to Banks_Total
Bank = Banks(Bank_Count)
Account_Total = UBound(Bank)
The last line is where my bug is. But if I wrote Ubound(GS) it would be totally fine. Why!!!?