vbscript 使用此代码段从Excel中的数据行创建动态数组。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 使用此代码段从Excel中的数据行创建动态数组。相关的知识,希望对你有一定的参考价值。

Sub DArrayCreator()
Dim wb As Workbook
Dim ws As Worksheet
Dim i, j, k As Integer

'Use this snippet for creating dynamic arrays from rows of data in Excel.
'Current snippet only allows for two columns of data.
'Enter source workbook location here
'Set wb = Workbooks.Open("C:\Users\Martin\Desktop\ArrayReplacer.xlsx")
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")

'Counts number of cells in column A
k = ws.Application.CountA(Range("A:A"))

Dim ListA(), ListB() As Variant
ReDim ListA(1 To k), ListB(1 To k)

For i = 1 To k
    ListA(i) = ws.Range("A1").Offset(i)
Next i

For i = 1 To k
    ListB(i) = ws.Range("B1").Offset(i)
Next i

'Indicates what values are included in your array.

Debug.Print "ListA has " & UBound(ListA) & " values."
Debug.Print "ListB has " & UBound(ListB) & " values."

'For i = LBound(ListA) To UBound(ListA)
 '   msg = msg & ListA(i) & vbNewLine
'Next i
'Debug.Print "The values of my dynamic array (ListA) are: " & vbNewLine & msg

End Sub

以上是关于vbscript 使用此代码段从Excel中的数据行创建动态数组。的主要内容,如果未能解决你的问题,请参考以下文章