Arrays 数组VBA中的访问列
我的代码从分配工作表和获取行数开始Arrays 数组VBA中的访问列,arrays,vba,excel,Arrays,Vba,Excel,我的代码从分配工作表和获取行数开始 Set ws2 = ThisWorkbook.Worksheets("Sheet2") lastRow22 As Long lastRow22 = ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Row 下面是将整个列放入从第1列到第80列的数组中 Dim arrEntireWs2() as Variant With ws2 arrEntireWs2 = .Range(.Cells(2,1),.Cells(las
Set ws2 = ThisWorkbook.Worksheets("Sheet2")
lastRow22 As Long
lastRow22 = ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Row
下面是将整个列放入从第1列到第80列的数组中
Dim arrEntireWs2() as Variant
With ws2
arrEntireWs2 = .Range(.Cells(2,1),.Cells(lastRow22,80)).Value
End With
然后我循环通过它
Dim lngArrEntireWs2Index as Long
For lngArrEntireWs2Index = LBound(arrEntireWs2,1) to Ubound(arrEntireWs2,1)
'Things I want to do
Next lngArrEntireWs2Index
我的问题是如何获取循环行中某一列的值?比如,在循环过程中,如何获取第10列中的内容?这就是您要查找的内容
Dim lngArrEntireWs2Index as Long
For lngArrEntireWs2Index = LBound(arrEntireWs2,1) to Ubound(arrEntireWs2,1)
If arrEntireWs2(lngArrEntireWs2Index, 10) Then
debug.print; arrEntireWs2(lngArrEntireWs2Index, 10)
End if
Next lngArrEntireWs2Index
我觉得这样更好
Dim ws2 as workbook
Set ws2 = ThisWorkbook.Worksheets("Sheet2")
Dim arr2 as Variant
With ws2
arr2 = .UsedRange
End With
Dim i as Long
For i= LBound(arr2,1) to Ubound(arr2,1)
If arr2(i, 11) Then
debug.print; arr2(i, 11)
End if
Next i
仅供参考,命名约定有点笨重,难以阅读