我正在尝试检查指定范围内的任何单元格中是否包含数据,以便可以移至项目的下一步并打印出数据(如果有)。假设我有一个范围A1:F39,如何检查这些单元格中是否有任何数据?此刻,我一个接一个地遍历整个单元格范围,遍历整行,然后再切换到下一列,并查看该单元格是否为空白。如果有更好的方法,我将不胜感激,谢谢!!
Dim RowCounter As Integer
Dim ColumnTraversing As Integer
Dim PopulatedCounter As Integer
RowCounter = 1
ColumnTraversing = 1
PopulatedCounter = 0
With ThisWorkbook.Worksheets("Test")
While (ColumnTraversing <= 6)'column looper
While (RowCounter < 40) 'Row Looper
'
If (.Cells(RowCounter, ColumnTraversing).Text <> "") Then
i = i + 1
End If
RowCounter = RowCounter + 1
Wend
ColumnTraversing = ColumnTraversing + 1
RowCounter = 1
Wend
If (i > 0) Then
PopulatedCounter = PopulatedCounter + 1
End If
End With