Consulting

Results 1 to 4 of 4

Thread: Solved: Find text in columns

  1. #1

    Solved: Find text in columns

    Hi
    Here is my problem

    I want to search and find text i column A and with the text that is in the first cell in column B (B1) and then go to B2 and so on.......

    My code just search the text within B1 but how do a make the code so it go to the next cell in B column



    This is my "code"

    Dim R As Range, FindAddress As String

    With Sheets(1).Range("A:A")

    Set R = .Find(Range("C1"))

    If Not R Is Nothing Then

    FindAddress = R.Address
    Do

    R.Select

    Set R = .FindNext(R)


    Loop While Not R Is Nothing And R.Address <> FindAddress
    End If
    End With

    'delete memory
    Set R = Nothing


    Please ..... Thanks
    Last edited by u25103; 02-24-2008 at 01:22 PM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim LastRow As Long
    Dim i As Long
    Dim R As Range, FindAddress As String

    With Sheets(1)

    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

    For i = 1 To LastRow

    Set R = Nothing
    Set R = .Find(.Cells(i, "B").Value)
    If Not R Is Nothing Then

    R.Select
    End If
    Next i
    End With

    'delete memory
    Set R = Nothing
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Find text

    Thanks.

    But the code dosen't find any text in cell b1. I did a "interior.colorindex" and it only highlighted the empty cells in range i want it to search in. "With Sheets(1).Range("A:A")


    Dim LastRow As Long
    Dim i As Long
    Dim R As Range, FindAddress As String

    With Sheets(1).Range("A:A")

    LastRow = .cells(.Rows.Count, "B").End(xlUp).Row

    For i = 1 To LastRow

    Set R = .Find(.cells(i, "B").Value)

    If Not R Is Nothing Then
    Do

    R.Select
    Selection.Interior.ColorIndex = 40
    Set R = .FindNext(R)
    Loop While Not R Is Nothing And R.Address <> FindAddress

    End If
    Next i
    End With

    'delete memory
    Set R = Nothing


    ?????????

  4. #4
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location

    What's in column B?

    I think you need to; find - then perform an act - then find again. right?

    I attacheted an example with a listbox to populate column B then find the item selected in column A.


    (Find_Function, via Aaron T. Blood)

Posting Permissions

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