mardi 19 avril 2016

Use VBA union function to conditionally add cells to range

I am trying to add certain cells to their respective ranges depending on their interior colour using the union method. The code I am using is as follows:

For Each cell In EntirePossibleRange

    If cell.Interior.Color = RGB(132, 151, 176) Then
        Set AccessabilityRange = Union(AccessabilityRange, Range("B" & cell.Row)
    Else If cell.Interior.Color = RGB(244, 176, 132) Then
        Set ConsistencyRange = Union(ConsistencyRange, Range("B" & cell.Row)
    Else If cell.Interior.Color = RGB(255, 217, 102) Then
        Set EfficacyRange = Union(EfficacyRange, Range("B" & cell.Row)
    Else cell.Interior.Color = RGB(191, 191, 191) Then
        Set WiderImpactsRange = Union(WiderImpactsRange, Range("B" & cell.Row)
    End If


Next cell

End Sub

However the code won't run and throws up a syntax error. I cannot figure out what the syntax error is though.

Aucun commentaire:

Enregistrer un commentaire