gpt4 book ai didi

vba - 循环遍历公式 Excel VBA

转载 作者:行者123 更新时间:2023-12-02 03:42:34 24 4
gpt4 key购买 nike

我需要检查现有公式并删除整行(如果其中没有减号)。有没有办法逐个字符地遍历公式,或者有另一种方法来识别公式中是否有“-”?

Sub clearvalidation()
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Sheets
Set vali = ws.Cells.Find("Validation", LookIn:=xlValues, LookAt:=xlPart)
If Not vali Is Nothing Then
fr = vali.Row + 2
lr = ws.Cells(fr + 1, 6).End(xlDown).Row
For exclrow = fr To lr
For Each char In ws.Cells(exclrow, 7)
If char = "-" Then
check = "ok"
Exit For
End If
Next char
If check <> ok Then check = "delete"
Select Case check
Case Is = "ok"
Stop
Case Is = "delete"
Stop
End Select
Next exclrow
End If
vali = Empty
Next ws

End Sub

最佳答案

要快速浏览每个工作表并删除 G 列中不包含连字符的行,AutoFilter Method可能效果最好。

Sub Macro1()
Dim w As Long

For w = 1 To Worksheets.Count
With Worksheets(w)
If .AutoFilterMode Then .AutoFilter = False
With .Cells(1, 1).CurrentRegion
.AutoFilter Field:=7, Criteria1:="<>*-*"
With .Resize(.Rows.Count - 1, .Columns.Count).Offset(1, 0)
If Application.Subtotal(103, .Cells) Then
.Cells.EntireRow.Delete
End If
End With
End With
End With
Next w

End Sub

关于vba - 循环遍历公式 Excel VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33799254/

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