简体   繁体   中英

How do I search through a Range of cells in VBA for excel for values that are a strings not equal to “phrase”

I've been asked to program a simple enough task in VBA, I usually work with Java and have never even looked at VBA. I'm not really getting what I want when i google it so I thought i'd ask here.

How do I search through a Range of cells in VBA for excel for values that are a strings not equal to "phrase"

Apologies for what seems like such a simple question but this isnt my area, any feedback is much appreciated

Martin

Please see below. You can change your range accordingly

Sub searchfor()
Dim rng As Range
Set rng = Range("A1:B100") ' Identify your range
    For Each c In rng.Cells
        If c.Value <> "" And c.Value <> "phrase" Then '<--- Will search if the cell is not empty and not equal to phrase. If you want to check empty cells too remove c.value <> ""
            MsgBox (c.Address & "Not Equal") '<---- Your code goes here
        End If
    Next c
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