Double For Each Loop in VBA Excel

Viewed 3555

I work on Excel, with 2 sheets called "Releves" and "Observations". I want to color a column of the Releves sheets based on the content of the cells of a column of the Observations Sheets.

The statement would be this one :

if cells of my_column_observations_sheet are not empty, put a yellow color in my_column_releves_sheet.

I made a double for each loop but it does not work. When I run the script, all the cells of the my_column_releves_sheet are colored, even if the cells of my_column_observations_sheet are empty...

Here is my script :

Sub condition()

Dim espece As Range
Dim num_releve As Range

ThisWorkbook.Sheets("Relevé").Activate
Set num_releve = ActiveSheet.Range("G3:G6")

ThisWorkbook.Sheets("Observations").Activate
Set espece = ActiveSheet.Range("B3:B6")

    For Each i In espece
        For Each j In num_releve
        If Not IsNull(i.Value) Then j.Interior.ColorIndex = 6
        Next
    Next
End Sub
1 Answers
Related