+ Reply to Thread
Results 1 to 16 of 16

highlight entire row when contains certain letters in word(s) in the whole worksheet

  1. #1
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Question highlight entire row when contains certain letters in word(s) in the whole worksheet

    I want a vba that can highlight the entire row when certain letters were found in word(s) in cells
    i found the below code, but it works when there is an exact match ONLY.

    PHP Code: 
    Sub colorentirerow_ifvalue()
     
     
    Dim r As Variant
     Dim k 
    As Variant
     Dim i 
    As Variant

    Range
    ("A1"ActiveCell.SpecialCells(xlLastCell)).Select
    For Each r In Selection
    If r.Value Like "HUA" Then
    r
    .EntireRow.Interior.ColorIndex 22
    End 
    If
    Next

    Range
    ("A1"ActiveCell.SpecialCells(xlLastCell)).Select
    For Each k In Selection
    If k.Value Like "KIND" Then
    k
    .EntireRow.Interior.ColorIndex 21

    End 
    If
    Next

    Range
    ("A1"ActiveCell.SpecialCells(xlLastCell)).Select
    For Each i In Selection
    If i.Value Like "THANKS" Then
    i
    .EntireRow.Interior.ColorIndex 20

    End 
    If
    Next

    End Sub 
    i need
    1. partial matches to be highlight too.
    e.g. A cell contains "CHANGHUA" or "HUACHANG" to be found and highlight the entire row
    2. treats uppercase or lowercase as the same value.
    e.g. A cell contains "hua" or "Hua" to be found and highlight the entire row

    THANKS!

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    Maybe if you change this part of the code

    Please Login or Register  to view this content.
    In

    Please Login or Register  to view this content.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    Thanks oeldere!
    it solved my first issue.
    but it still can not find "hua" or "Hua"

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    This has not been tested, but a filter approach might work.

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    A couple of things:
    1) selecting hinders performance
    2) if you have repetitive blocks of code, it's a good idea to compress them

    This isn't working, so perhaps it can be tweaked a bit...I'm sure the idea is dead on target:
    Please Login or Register  to view this content.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  6. #6
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    Hi JOHN H. DAVIS, it doesnt work, it only highlight the first row

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    I just tested it and it worked for me. Which cell did you select as the activecell in your range?

  8. #8
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    to tlafferty

    it doesnt work either.
    nothing is highlighted
    Last edited by purin0c0; 09-06-2012 at 03:58 PM.

  9. #9
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    to JOHN H. DAVIS
    i tried,it works only if the filtered words ("HUA" ,"KIND" and "THANKS") in Column A. In my case, it can be all over the entire worksheet.
    Can it be fix?
    Last edited by purin0c0; 09-06-2012 at 05:28 PM.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    How many columns do you have? This will handle 20, but you can increase the variable. There probably are a lot better ways.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    i have 39 columns from column A to column AM

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    Then change this:

    For i = 1 To 20

    To this:

    For i = 1 To 39

  13. #13
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    I tried with the code below

    PHP Code: 
    Sub purin0c0()

    Dim i As Long

    For 1 To 39

    Range
    (Cells(1i), ActiveCell.SpecialCells(xlCellTypeLastCell)).AutoFilter Field:=1Criteria1:="=*HUA*"
    Range(Cells(1i), ActiveCell.SpecialCells(xlCellTypeLastCell)).SpecialCells(xlCellTypeVisible).EntireRow.Interior.ColorIndex 22
    ActiveSheet
    .AutoFilterMode False

    Range
    (Cells(1i), ActiveCell.SpecialCells(xlCellTypeLastCell)).AutoFilter Field:=1Criteria1:="=*KIND*"
    Range(Cells(1i), ActiveCell.SpecialCells(xlCellTypeLastCell)).SpecialCells(xlCellTypeVisible).EntireRow.Interior.ColorIndex 21
    ActiveSheet
    .AutoFilterMode False

    Range
    (Cells(1i), ActiveCell.SpecialCells(xlCellTypeLastCell)).AutoFilter Field:=1Criteria1:="=*THANKS*"
    Range(Cells(1i), ActiveCell.SpecialCells(xlCellTypeLastCell)).SpecialCells(xlCellTypeVisible).EntireRow.Interior.ColorIndex 20
    ActiveSheet
    .AutoFilterMode False


    Next i

    End Sub 
    It did highlighted the lines i need.
    but it also highlighted my first row and all blank rows after the active row to ColorIndex = 20

    can it be fixed?

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    Maybe:

    Please Login or Register  to view this content.
    Again, probably not the best way.

  15. #15
    Registered User
    Join Date
    09-06-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    that works great!!
    THANKSS!!! JOHN!!!

  16. #16
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: highlight entire row when contains certain letters in word(s) in the whole worksheet

    You're welcome. Glad too help out and thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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