Find Specific word and then highlight range of cells

I need to be able to find either a word or a word that starts with xx and then highlight a specific range.

I have this code but it only highlights the word. Could someone assist please. I need to be able to Highlight the row from A to R

Dim vCells As Range
   
    Sheets("Result").Select
    For Each vCells In Range("A1:A2000").Cells
        If Left(vCells.Text, 2) = "Ev" Then
            vCells.Interior.ColorIndex = 43
            vCells.Borders.LineStyle = xlContinuous
            vCells.Borders.Weight = xlThin
        End If
    Next vCells

many thanks
JagwarmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

[ fanpages ]IT Services ConsultantCommented:
Hi,

Please change you existing code to read:

Public Sub Q_28249024()

  Dim vCells                                            As Range
    
  Worksheets("Result").Select
  
  Range("A1:R2000").Interior.ColorIndex = xlNone        ' *** ADDED
  Range("A1:R2000").Borders.LineStyle = xlNone          ' *** ADDED
  
  For Each vCells In Range("A1:A2000").Cells
      
      If Left(vCells.Text, 2) = "Ev" Then
         Range(Cells(vCells.Row, "A"), Cells(vCells.Row, "R")).Interior.ColorIndex = 43             ' *** CHANGED
         Range(Cells(vCells.Row, "A"), Cells(vCells.Row, "R")).Borders.LineStyle = xlContinuous     ' *** CHANGED
         Range(Cells(vCells.Row, "A"), Cells(vCells.Row, "R")).Borders.Weight = xlThin              ' *** CHANGED
     End If
     
  Next vCells

End Sub

Open in new window


Please note that I have added two lines to "reset" all the cells in the range [A1:R2000] before the loop begins.


BFN,

fp.
0
Rgonzo1971Commented:
Hi,

pls try

Dim vCells As Range
    
    Sheets("Result").Select
    For Each vCells In Range("A1:A2000").Cells
        If Left(vCells.Text, 2) = "Ev" Then
            vCells.Resize(1, 18).Interior.ColorIndex = 43
            vCells.Resize(1, 18).Borders.LineStyle = xlContinuous
            vCells.Resize(1, 18).Borders.Weight = xlThin
        End If
    Next vCells

Open in new window

Regards
0
Rob HensonFinance AnalystCommented:
How about adopting Conditional Formatting?

The formatting can use a formula to determine whether a string is found within the cell.

The string to look for can be in another cell and referred to in the formula.

Thanks
Rob H
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JagwarmanAuthor Commented:
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.