在数组VBA中访问列

我的代码从分配表单并抓取行数开始

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