Consulting

Results 1 to 5 of 5

Thread: Using an array to hold criteria

  1. #1
    VBAX Contributor compariniaa's Avatar
    Joined
    Jun 2006
    Location
    Santa Clarita, CA
    Posts
    117
    Location

    Using an array to hold criteria

    say I want to delete/select/whatever certain rows of cells

    I have an array with 4 items. the four items are product1, product2, product3, product4

    If I want to do something (let's say copy) to all of the rows containing one of those four products, how would I go about doing that?

  2. #2
    Hi

    See if this gets you going. It will cycle through the entries in the array, and if it finds a match, it will put DONE SOMETHING HERE in column A for that match.


    Sub aaa()
      Dim FindIt As Range
      Dim ProdArr As Variant
      ProdArr = Array("product1", "product2", "product3", "product4")
      For i = LBound(ProdArr) To UBound(ProdArr)
        Set FindIt = Cells.Find(what:=ProdArr(i))
        If Not FindIt Is Nothing Then
            firstadd = FindIt.Address
            Do
                Cells(FindIt.Row, 1).Value = "DONE SOMETHING HERE"
                Set FindIt = Cells.FindNext(FindIt)
            Loop Until FindIt.Address = firstadd
        End If
      Next i
    End Sub


    Tony

  3. #3
    VBAX Contributor
    Joined
    Jul 2005
    Posts
    169
    Location
    Tony,

    I'm afraid that your code possibly go into endless loop when the firstadd is in Col.A.

    I usually do not add the line of FindIt Is Nothing, however you need it in your case,
    becaseu you are changing the value of possible first found cell.

    Loop Unitl FinIt.Address = firstadd Or FindIt Is Nothing

  4. #4
    Jindon

    Fair enough. I usually don't use the generic cells.find either, but given the lack of OP information on structure, I just gave some starting code.

    Tony

  5. #5
    VBAX Contributor compariniaa's Avatar
    Joined
    Jun 2006
    Location
    Santa Clarita, CA
    Posts
    117
    Location
    Tony, that's what I needed! Thanks, and sorry about the poor description. Coming back to it now I can see how it was a little vague.

Posting Permissions

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