简体   繁体   中英

Excel VBA - Find 0

I'm stuck with what is probably a stupid question. "How to find a cell where the formula returns an answer of 0 (zero) Column A contains x rows of formula adding each row Column B to D = SUM(B4:D4) Im trying to delete all rows where is finds this value.

Columns("A:A").Select
Selection.Find(What:="0", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    , SearchFormat:=True).Activate
strDelRow = Activecell.Row
Rows("" & StrDelRow &":" & StrDelRow).Select
Selection.Delete Shift:=xlUp

...but - it can find the zeros as they are in a formula? Anyone to possibly help?

Many thanks,

Ian

Yes it can find formulas returning zero.

Looks like you are selecting the entire column A and looking for zeros, try change the code as follows

Range("A1").Select 'Start at the top

Range("A:A").Find(What:="0", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    , SearchFormat:=False).Activate

Give this a try:

Sub dural()
    Dim N As Long, NN As Long
    NN = Cells(Rows.Count, "A").End(xlUp).Row
    For N = NN To 1 Step -1
        If Cells(N, 1).Value = 0 Then
            Cells(N, 1).EntireRow.Delete
        End If
    Next
End Sub

将特殊值复制/粘贴到另一列,然后将其用于删除代码

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM