如何始终在With xx end With
中检测隐藏的列和行?我的代码的当前变量值取决于隐藏或不隐藏的行和行。这阻止了我的代码正常工作。VBA Excel在With x End With循环中检测始终隐藏的行和列?
With myMatrixSheet
lastRow = .Range("B" & .Rows.Count).End(xlUp).row
lastColumn = .Cells(7,.UsedRange.Columns.Count).End(xlToLeft).column + 1
End With
我的解决,最终的代码看起来喜欢下面
With myMatrixSheet
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).row
Else
lastRow = 1
End If
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastColumn = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).column
Else
lastColumn = 1
End If
End With
嗨,你的例子计算工作表中所有可能的行。我只想要最后一行是文本。 – AratioD
@AratioD将'Cells'部分更改为您使用的范围...像'Columns(3)' –