Set variable name with string variable in VBA

落花浮王杯 提交于 2019-12-13 03:35:05

问题


I have to create many variables inside a loop, so I need to create generic variable names (note, for the purpose of my code, i can't just append the objects i want to create to a list or collection)

The code I was thinking looks something like this (n is a user defined variable, and its an integer)

Dim var_name As String

For i = 1 To n
    var_name = "test" & i
    Set var_name = Range(Cells(1, 1), Cells(i * 2, i))
Next i

I would like to obtain variables like this:

  • test1 being a range from A1 to B2
  • test2 being a range from A1 to C4
  • test3 being a range from A1 to D6
  • .... testn being a range from A1 to whatever

They dont necesarily have to be range, all I really want is to declare a variable name using a string stored in another variable

来源:https://stackoverflow.com/questions/50614408/set-variable-name-with-string-variable-in-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!