Consulting

Results 1 to 7 of 7

Thread: problem comparing cells based on a condition

  1. #1
    VBAX Regular
    Joined
    Mar 2009
    Posts
    38
    Location

    problem comparing cells based on a condition

    hello guys

    i'm using a table like this one :


    A | B

    Part1 4512654_04
    Part2 4512654_03
    Part3 4512444_01
    Part4 4512654_04
    .
    .
    PartN 4512654_02

    I want to check if the 6 last numbers of a ref. number (Column B) are similar with the last 6 numbers of another ref. number.

    for example: Part1 | "654_04" and Part4 "654_04" ; if so color them in red.

    Thanks in advance for your help
    regards

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]
    Sub Test()
    Dim rng As Range, cel As Range, i As Long
    Set rng = Range(Cells(1, 2), Cells(Rows.Count, 2).End(xlUp))
    For Each cel In rng
    For i = 2 To rng.Cells.Count
    If Right(cel, 6) = Right(rng(i), 6) And cel.Address <> rng(i).Address Then
    cel.Interior.ColorIndex = 3
    rng(i).Interior.ColorIndex = 3
    End If
    Next
    Next
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Mar 2009
    Posts
    38
    Location
    Thanks a lotmdmackillop
    regards

  4. #4
    VBAX Regular
    Joined
    Mar 2009
    Posts
    38
    Location
    hey mdmackillop, hey everyone

    what if i wanted to compare like so :
    the last three chars before "_" sign

    for example: Part1 | "654"" and Part4 | "654" ; if so color them in red.

    your help is appreciated
    regards

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You can use Mid and Find to find and return strings from within strings. Check these out in the Help file.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Regular
    Joined
    Mar 2009
    Posts
    38
    Location
    that's ok mdmackillop, but i'm not a specialist, some help will be appreciated...

    i can make it but it won't work, i always get errors, you see...

    thanks in advance

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Please post your code.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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