Assuming the search data is in the C column of the Sheet(1) and You will search in the Sheet(2), this is code with the function . Find
Dim Rng As Range, rng2 As Range
ncell = Sheets(1).Cells(Sheets(1).Rows.Count, 3).End(xlUp).Row
Set Rng = Sheets(2).Cells 'range para procurar
Set rng2 = Rng(1, 1)
For j = 1 To ncell
pesquisar = Sheets(1).Cells(j, 3).Value 'referência de procura na coluna 3 (ou seja, C)
With Rng
Set cellFound = .Find(what:=pesquisar, After:=rng2, LookIn:=xlValues)
If Not cellFound Is Nothing Then
FirstAddress = cellFound.Address
Do
Sheets(2).Range(cellFound.Address).Interior.ColorIndex = 4
Set cellFound = .FindNext(cellFound)
Loop While Not cellFound Is Nothing And cellFound.Address <> FirstAddress
End If
End With
Next
End Sub
Another alternative is the use of an Object Dictionary, this is faster and optimizes the processing time. Recommended for spreadsheets with lots of data.
Look at the remark I added please. Thanks anyway
– Gustavo Dawson
This conditional formatting will continue to work. And if you use Excel tables for the validation data (code in the table) you will get even better.
– Evert
I select the cell and drag to another position.. Usually when I drag, the cell that is empty loses its properties
– Gustavo Dawson
@Gustavodawson I tested here and does not lose when moving a cell with the mouse to another cell... I will try to make a gif and post in the answer.
– Evert
Follow my model https://1drv.ms/x/s! Aiqrcjor1qmhmi4njhswugfqdkzjka please note that I am using Excel 2013, however I believe that until 2010 tb is the same way. Coming home I can test until 2007 and post comment.
– Evert
do the following test and you will see the problem I find: Take this sheet that you sent me and drag one of the cells that contains "P9" for example, when dragging it remains "green", but the old cell where "P9" was lost property, if you write "P9" in the old cell again he does not paint green.
– Gustavo Dawson
@Gustavodawson this will only happen if where you are dragging the cell does not have the same formatting. Do the same test there by dragging to a location where you have the same desired formatting and you will see that it works.
– Evert