|
刚学的vba数组解法
Private Sub CommandButton1_Click()
Dim xm() As String, Arr() As String, Temp() As String '声明变量
Dim s%, r% '声明单值变量
On Error Resume Next
ReDim Arr(256)
For s = 1 To 256
Arr(s) = ActiveSheet.Cells(3, s)
Next
zs = UBound(Arr)
For s = 0 To zs
If Arr(s) <> "" Then
Temp = Filter(xm, Arr(s)) '搜索数组
If UBound(Temp) = -1 Then '如果未找到
r = r + 1 '序号,自增1
ReDim Preserve xm(1 To r) '定义动态数组大小
xm(r) = Arr(s) '把姓名复制到数组XM()中。
If r = 10 Then Exit For
End If
End If
Next
Range("K6:T6") = xm
End Sub |
|