- 帖子
- 150
- 主題
- 43
- 精華
- 0
- 積分
- 235
- 點名
- 113
- 作業系統
- WIN10
- 軟體版本
- 2010
- 閱讀權限
- 20
- 性別
- 男
- 來自
- 台灣
- 註冊時間
- 2011-6-21
- 最後登錄
- 2025-5-5
     
|
6#
發表於 2021-2-22 11:45
| 只看該作者
剛學VBA有很多要學習,感謝各位指導,經調整後以下是我要的語法,謝謝大家.
Dim i&, j&, k%
Dim arr As Variant
Dim MAS As Variant
MAS = Cells(Rows.Count, 1).End(xlUp).Row
'Dim arr1(1 To 100, 1 To 2) '原稿
ReDim arr1(1 To MAS, 1 To 2) '調整後的語法
'arr = [a2:d100] '原稿
'arr = ["a2:d" & MAS ]
arr = Range(Cells(2, 1), Cells(MAS, 4).Address) '調整後的語法
For i = 1 To UBound(arr)
If arr(i, 1) <> "" Then
If arr(i, 1) = Cells(3, "e") And arr(i, 2) = Cells(3, "f") Then
k = k + 1
arr1(k, 1) = arr(i, 3)
arr1(k, 2) = arr(i, 4)
End If
End If
Next i
Cells(3, "h").Resize(UBound(arr1), 2) = arr1 |
|