我有一個全域變數,它在 Locals 視窗中顯示為 Variant/Variant(1 到 33, 1 到 9)。所以它是一個二維陣列,但是當我嘗試對陣列中的每個陣列進行訪問時,我無法訪問整個陣列,只能訪問單元格值
Public myRows As Variant
Public myTable As ListObject
Sub SendEmails()
Dim X As Long
Dim Row As Variant
SetMyTable
For Each Row In myRows
Debug.Print CheckRow(Row)
Next Row
End Sub
編輯:添加 CheckRow 函式
Function CheckRow(Row As Variant) As Boolean
Dim IsRowValid As Boolean
IsRowValid = True
If IsEmpty(Row(1)) = True Then
IsRowValid = False
End If
If IsEmpty(Row(2)) = True Then
IsRowValid = False
End If
If IsEmpty(Row(3)) = True Then
IsRowValid = False
End If
If IsEmpty(Row(4)) = True Then
IsRowValid = False
End If
If IsEmpty(Row(5)) = True Then
IsRowValid = False
End If
CheckRow = IsRowValid
End Function
uj5u.com熱心網友回復:
檢查陣列的行
- 由于您無法輕松傳遞陣列的行,因此請傳遞“整個事物”和行索引。
Public myRows As Variant
'Public myTable As ListObject ' irrelevant
Sub SendEmails()
'SetMyTable ' don't know what that does
Dim r As Long
For r = 1 To UBound(myRows, 1) ' loop through the rows
Debug.Print CheckRow(myRows, r)
Next r
End Sub
Function CheckRow(ByVal Data As Variant, ByVal RowIndex As Long) As Boolean
Dim c As Long
For c = 1 To UBound(Data, 2) ' loop through the columns
' Note that 'CheckRow' is initially (by default) equal to 'False'.
If IsEmpty(Data(RowIndex, c)) Then Exit Function
Next c
CheckRow = True ' all values in the row are not empty
End Function
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/491502.html
