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

How to highlight only the first instance from the loop

ThrottleWorks

Excel Ninja
Hi,
I have a loop. This loops checks around 50 condition in a run.
For example, the first condition from the loop will check if the Cell A5 has value as “Yamaha” if yes then it will highlight the cell.
Then macro will move to next condition, if value in Cell B2 is Honda then highlight the cell.
My problem is once a cell is highlighted in Column A, say A5, macro should not repeat the procedure for Column A.
If cell A5 and A6 both has value as “Yamaha” macro should highlight only cell A5 and move on to the next condition in the loop.
I want to highlight only the first instance from each condition and ignore rest.
Can anyone help me in this please.

Code:
Set FindCell = Range_2.FindSheet.Range("A5").Value)
    If FindCell Is Nothing Then
            Application.StatusBar = " 'aaa' is not present in Sample File !"
        Else
            If ResultSheet.Cells(i, MyColumns(FindSheet.Range("a5")).Column) = "" Then
                ResultPutSheet.Cells(i, MyColumns(FindSheet.Range("a5")).Column).Interior.Color = 1
            End If
If ResultSheet.Cells(i, MyColumns(FindSheet.Range("a5")).Column).Interior.Color = 1 Then
    Define action here
            End If
         
End If: Set FindCell = Nothing
 

Attachments

  • Loop.xlsb
    7.7 KB · Views: 1
You might need to put an IF condition in that checks the colour of the previous cell. Something like.
Code:
If Range("A" & ActiveCell.Row).Interior.Color = 1 Or Range("B" & ActiveCell.Row).Interior.Color = 1 Then
    'Skip to next cell
Else
    ActiveCell.Interior.Color = 1
End If
 
Back
Top