【发布时间】:2021-02-06 05:01:39
【问题描述】:
我试图让这个循环以相反的顺序检查 xCol,或者从右列到左边。它在没有 Step -1 的情况下工作(从左到右),但是当我添加 Step -1 时什么都不做。
Sub Email()
Dim xSheet As Worksheet
Dim xRow As Integer
Dim xCol As Integer
Dim lastRow As Integer
Dim lastCol As Integer
Set xSheet = Excel.Worksheets("Approval Process")
lastRow = xSheet.UsedRange.Rows.Count
lastCol = xSheet.UsedRange.Columns.Count
For xRow = 2 To lastRow
For xCol = 3 To lastCol Step -1
If xSheet.Cells(xRow, xCol).Value <> "" Then
MsgBox xRow & "," & xCol
Exit For
Else
MsgBox "Blank"
End If
Next xCol
Next xRow
End Sub
单元格 (C2,H5) 有“是”字样或空白。
最终目标是让循环返回每行中包含数据的最后一个单元格的行号和列号。
【问题讨论】:
-
确保将
Integer更改为LongExcel 的行数超出Integer的处理能力!由于使用Integer没有任何好处,我推荐always to useLonginstead