0
votes

Can anyone please help on Excel VBA coding, I want to change the colors of cells when the values are changed on single go with copy paste on certain range, say "A1:B10"

I am able to perform for a single cell copy paste as below , but not sure how to perform the same for multiple cells,

If Not Intersect(Target, Range("B2:K20")) Is Nothing Then
    If oldValue <> Target.Value Then
        Target.Interior.Color = RGB(184, 245, 198)
    End If
End If
1
your code does do multiple cells. You can add another If Not Intersect for an additional range.... and along the lines of the current answer below you can have Range("B2:K20").Interior.Color = if you want all the cells in the intersect coloured.QHarr
what is oldValue? is this inside some Worksheet_Change() event handler and you want to monitor any actual change? you may want to add some more detailDisplayName

1 Answers

0
votes

You will need to loop through your Target, like in the code below:

Dim C As Range

If Not Intersect(Target, Range("B2:K20")) Is Nothing Then
    ' loop through cells in range
    For Each C In Target
        If oldValue <> C.Value Then
            C.Interior.Color = RGB(184, 245, 198)
        End If
    Next C
End If