Consulting

Results 1 to 6 of 6

Thread: Solved: Find text & Mark findings

  1. #1

    Solved: Find text & Mark findings

    Hello friends,

    Please look at the data in column "J". I need your help in creating a code. The would look for "10714", every time it finds it, it marks "X", in the column "K" (nearby cell).

    Thank you so much!
    Nawaf

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    I don't see any file attached, but I'm guessing the code should look something like this:
    [vba]Dim c As Range
    For Each c In Sheet1.Range("J1:" & Sheet1.Columns("J").SpecialCells(xlLastCell).Address)
    If c = 10714 Then c.Offset(, 1) = "X"
    Next
    [/vba]

  3. #3
    Thanks a lot,
    One problem the "10714" that I am looking for is not in the beginning nor is it at the end of the cell. that is why the code is still not working. sorry, the attachment is there now.

    Thanks again!
    Nawaf

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    You could use InStr() to see if "10714" exists anywhere inside the string.

    [vba]Sub ex()
    Dim lngLastRow As Long
    Dim rcell As Range

    With ThisWorkbook.Worksheets("Sheet1")
    lngLastRow = .Range("J" & .Rows.Count).End(xlUp).Row
    End With


    For Each rcell In ThisWorkbook.Worksheets("Sheet1").Range("J2:J" & lngLastRow)
    If Not InStr(1, rcell.Text, "10714", vbTextCompare) = 0 Then
    rcell.Offset(, 1).Value = "X"
    End If
    Next
    End Sub[/vba]

  5. #5
    Thank a lot to all, that certainly made my day!

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Greetings,

    You are most welcome of course. Once a question is Solved, please mark it Solved. You can do this by clicking the Thread Tools button that is at the top of your first post; and select the mark as solved option.

    Mark

Posting Permissions

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