gpt4 book ai didi

excel - 使用 .Find 引用单元格时未设置对象变量或 With block 变量

转载 作者:行者123 更新时间:2023-12-04 20:53:46 38 4
gpt4 key购买 nike

这以前有效,但已停止工作:

Sub LeanCut()
Dim lrow As Long

Cells.Find(What:="~*~*~* Total*", After:=[A1], LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
Rows(ActiveCell.Row & ":" & Rows.Count).Delete

lrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Range("A10:I" & lrow).Select

End Sub

我在线收到运行时错误 91
Cells.Find(What:="~*~*~* Total*", After:=[A1], LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate

该脚本应该找到包含“~~~ Total”的单元格并将其连同其下方的所有内容一起删除,然后选择其上方的范围。

最佳答案

更新工作表名称 (????)

Option Explicit

Sub LeanCut()

Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("????")
Dim lrow As Long, Found As Range

lrow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
Set Found = ws.Cells.Find(What:="~*~*~* Total*", After:=ws.Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)

If Not Found Is Nothing Then
ws.Range(ws.Cells(Found.Row, 1), ws.Cells(lrow, 9)).Delete
Else
MsgBox "Value not found"
End If

End Sub

关于excel - 使用 .Find 引用单元格时未设置对象变量或 With block 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52706847/

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