+ Reply to Thread
Results 1 to 7 of 7

finding first 2 digits in a cell from a row and mark them orange

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    finding first 2 digits in a cell from a row and mark them orange

    Hi all,

    I have excel sheet where I have in a row some serian numbers. When the serial starts with 99, I need to mark this cell with orange. I just don't know how to pull this one. The numbers are in column E and the lengt of the column changes from time to time.

    Any help is more then welcome.

    Greetings.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: finding first 2 digits in a cell from a row and mark them orange

    Try this code...

    Sub ColorCellsBasedOnConditon()
    Dim nEndRw As Long, i As Long
    
    nEndRw = Cells(Rows.Count, "E").End(xlUp).Row
    
    Application.ScreenUpdating = False
    
    For i = 1 To nEndRw
       With Cells(i, "E")
          If Trim(.Value) = "99" Then .Interior.ColorIndex = 40
       End With
    Next i
    
    Application.ScreenUpdating = True
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: finding first 2 digits in a cell from a row and mark them orange

    Sixthsense : your solution seems to look if the entire value in the cell is "99" and then mark yellow. Megatronixs wants to know if the serial number starts with 99...
    I think the code below does what he's looking for.

    Sub test()
    For Each cell In Range("E1:E" & Range("E65536").End(xlUp).Row)
    If Left(Trim(cell.Value), 2) = "99" Then cell.Interior.ColorIndex = 40
    Next cell
    End Sub

  4. #4
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: finding first 2 digits in a cell from a row and mark them orange

    Hi,
    It works, but only if the cell has only 99 in it, if it starts with 998887, it does not find it. I need to select when a cell has a number that starts with 99........

    Thanks for you help, I really appriciate it ;-)

    Greetings

  5. #5
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: finding first 2 digits in a cell from a row and mark them orange

    Oops oversight error...

    replace this line
    If Trim(.Value) = "99" Then .Interior.ColorIndex = 40
    With

    If Left(Trim(.Value), 2) = "99" Then .Interior.ColorIndex = 40

  6. #6
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.85 (24051214))
    Posts
    8,830

    Re: finding first 2 digits in a cell from a row and mark them orange

    can you just fill the cell colour or are you looking to mark the characters , I dont think that can be done

    the fill for the cell would be conditional formatting

    =Left(cell,2)=99
    and colour orange

    now in case you alos have text , I have used
    =VALUE(LEFT(A1,2))=99

    see attached
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Austria
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: finding first 2 digits in a cell from a row and mark them orange

    Hi all,

    Thanks all for the fast help. JasperD is right, I needed to find a cell that starts with 99. So the solution from JasperD works perfect for my need.
    I just had no clue that the macro could be so simple (if you know the code). I'm still learning VBA and I must say that it still looks like Chinese to me ;-)

    Thank you all for your solutions.

    Greetings.

+ 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