[英]How to create variable based on no of column in an excel sheet
Below is the code to get no of last used column 下面的代码获取没有最后使用的列
Dim lastColumn As Integer
lastColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
which return suppose 6 .My use case is based on return value i want to create that no of long variable in vba. 该返回假定6。我的用例基于返回值,我想在vba中创建long变量。 How to do that please help
怎么做请帮忙
You should be defining 1 array variable of long data type. 您应该定义1个长数据类型的数组变量。
For eg. 例如。
Sub test()
' Get last column number
Dim lastColumn As Integer
lastColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
' Create a long data type array with limit equal last column number
Dim arrColVars(lastColumn) as Long
' Perform operations or assignment on variables
' arrColVars(0) = 123
' arrColVars(1) = 456
' ...
' arrColVars(n) = 789
End Sub
Note: 注意:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.