我的数组大小由其他一些函数决定。但是当我尝试使用变量定义数组的大小时,我收到错误“需要常量表达式”
我想定义数组的大小
Option Explicit
Sub Abcd()
Dim n_variables As Integer
n_variables = def()
MsgBox "n_variables" & n_variables
Dim abc(1 To n_variables) As Integer
End Sub
Function def()
def = 100
End Function
有什么方法可以以可变格式定义数组大小吗? 请任何人帮助我。
最佳答案
使用Redim
语句:
Dim n_variables As Integer
n_variables = def()
MsgBox "n_variables" & n_variables
Dim abc() As Integer
Redim abc(1 To n_variables) As Integer
关于vba - 如何定义变量中的数组大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36836123/