• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Color a range of cells that contain a specific text

somnath6309

New Member
The attached workbook contains a sheet named "ColorCells" where I wanted to color the cells in a SELECTION (Range E10:J10) that contain text "UH2" and generated the following code: (Kindly see Module 3 )
Sub colorcells()
Dim cell As Range
For Each cell In Selection
Cells.Find(What:="*UH2*", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Interior.Color = 255
Next cell
End Sub

The procedure colors all the cells in the worksheet that contains the text "UH2" but my motive was to color the cells in the selection only that contains the specific text. What will be the modified version in this regard ?
It may be that there may be more efficient code that performs the task and those are welcome to me.
Regards,
somnath63096
 

Attachments

  • ProfessionTaxCalculator.xlsm
    36.7 KB · Views: 1
Check this...

Code:
Sub colorcells()
Dim cell As Range
For Each cell In Selection
    If InStr(cell.Value, "UH2") Then cell.Interior.Color = 255
Next cell
End Sub
 
Back
Top