我需要 Excel 方面的帮助。我的问题是:如何获取此循环中每行的单元格 42?如:
For Each r In Sheets("Sheet2").UsedRange.Rows
sval = r.Cells(42)
If sval = "" Then
If r.Cells(6).Value <> "" And r.Cells(7).Value <> "" And r.Cells(9).Value <> "" And r.Cells(10).Value <> "" And r.Cells(11).Value <> "" And r.Cells(12).Value <> "" Then
MsgBox "wtehi"
r.EntireRow.Interior.ColorIndex = 0
Else
MsgBox "yallow"
emptyMand = "ok"
r.EntireRow.Interior.ColorIndex = 6
End If
End If
Next
最佳答案
要循环遍历工作表 ws
的所有行,并为每一行获取第 42 列上的单元格,您可以执行以下操作:
For Each rw in ws.UsedRange.Rows
cell = ws.Cells(rw.Row, 42)
Next
但是,下面的方法速度快两倍,并且更具可读性:
For i = 1 to ws.UsedRange.Rows.Count
cell = ws.Cells(i, 42)
Next
关于excel - 循环excel vba中的行并获取单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13882335/