Search code examples
vbaexcelexcel-2013

VBA how to create variable name containing variable


I have a macro with a variable number of players (1 and up). These players should be Player1, Player2, etc. How can I create variable names "on the fly"?

The best I can think of is something like this: a=a+1 Dim Player&(a)


Solution

  • Use Dictionary instead (treat keys as variable names): https://support.microsoft.com/en-us/kb/187234