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
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