gpt4 book ai didi

excel - 如何修复运行时1004 : No cells were found error

转载 作者:行者123 更新时间:2023-12-03 08:44:01 26 4
gpt4 key购买 nike

下面的代码(查找最后一行)以前工作正常,但是开始使

run time error 1004



(第三行)。我在这里读过类似的文章,但想在此特定代码上修复它。
With Sheet1.Range("A:A")

If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
' next line is where it errors
Set rng = .SpecialCells(xlCellTypeConstants, 1)
Set rng = rng.Areas(rng.Areas.Count)
lastrow = rng.Cells(rng.Cells.Count).Row
End If

End With

最佳答案

似乎无法在.specialcells方法中捕获错误。

可以使用以下解决方法。

With Sheet1.Range("A:A")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
' next line is where it errors
On Error Resume Next 'Avoid Error Call
Set Rng = .SpecialCells(xlCellTypeConstants, 1)
On Error GoTo 0 'Reset Error Ignoring Behavior
If Not Rng Is Nothing Then
Set Rng = Rng.Areas(Rng.Areas.Count)
lastrow = Rng.Cells(Rng.Cells.Count).Row
End If
End If
End With

关于excel - 如何修复运行时1004 : No cells were found error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58910398/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com