+ Reply to Thread
Results 1 to 3 of 3

Edit code to add extra criteria

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    438

    Edit code to add extra criteria

    How do I make this formula include searching for "ann" and "john" (in separate cells)?
    Thanks

    Sub Find_ANN()
        Dim rng As Range
        Dim what As String
        what = "ann"
        Do
            Set rng = ActiveSheet.UsedRange.Find(what)
            If rng Is Nothing Then
                Exit Do
            Else
                Rows(rng.Row).Delete
            End If
        Loop
    End Sub
    Last edited by VBA Noob; 03-19-2009 at 05:37 PM. Reason: better title and a spelling error

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe

    Sub Find_ANN()
        Dim rng As Range
        Dim i As Long
        Dim what As Variant
        what = Array("ann", "John")
        For i = 0 To UBound(what)
            Do
                Set rng = ActiveSheet.UsedRange.Find(what(i))
                If rng Is Nothing Then
                    Exit Do
                Else
                    Rows(rng.Row).Delete
                End If
            Loop
        Next i
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    438

    Smile

    Hey noob,

    Thanks much, I was able to alter the code to do exactly what I wanted. I don't know how you guys know all these codes off the top of your head, but kudos to all of you!

    Thanks much noob!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1