两种方法将数组内容装入

以下是两种方法

Private Sub CommandButton1_Click()
   Dim arr, arr1()
   arr = Range("a1:d6")
   Dim x, k
     For x = 1 To UBound(arr)
       If arr(x, 1) = "B" Then
         k = k + 1
         ReDim Preserve arr1(1 To 4, 1 To k)
         arr1(1, k) = arr(x, 1)
         arr1(2, k) = arr(x, 2)
         arr1(3, k) = arr(x, 3)
         arr1(4, k) = arr(x, 4)
       End If
     Next x
   Range("a9").Resize(k, 4) = Application.Transpose(arr1)
End Sub
Private Sub CommandButton2_Click()
  Dim arr, arr1(1 To 1000, 1 To 4)
  arr = Range("a1:d6")
  Dim x, k
    For x = 1 To UBound(arr)
      If arr(x, 1) = "B" Then
        k = k + 1
        arr1(k, 1) = arr(x, 1)
        arr1(k, 2) = arr(x, 2)
        arr1(k, 3) = arr(x, 3)
        arr1(k, 4) = arr(x, 4)
      End If
    Next x
  Range("a15").Resize(k, 4) = arr1
End Sub

发表评论

电子邮件地址不会被公开。 必填项已用*标注