Excel VBA将某列数值存入一个数组

Sub test()
Dim arr() As String                                  '定义动态数组
Dim n As Long
Dim i As Integer
n = Application.WorksheetFunction.CountA(Range("A:A")) '确定A列非空数据数量
ReDim arr(1 To n) As String                          '根据A列数据重新定义数组
For i = 1 To n Step 1
    arr(i) = Cells(i, 1)                              '给数组赋值
Next i
End Sub

本例中需要改进的是
1. 排除空值
2. 去重

你可能感兴趣的:(excel,vba,Excel)