'Make cells negative based upon the value of another
I'm able to colour cells based upon the value of another with the code below, which I found on this forum
Sub ColorMeElmo()
Dim i As Long, r1 As Range, r2 As Range
For i = 2 To 100
Set r1 = Range("D" & i)
Set r2 = Range("A" & i & ":C" & i)
If r1.Value = "Aankoop" Then r2.Interior.Color = vbRed
If r1.Value = "Verkoop" Then r2.Interior.Color = vbBlue
If r1.Value = "Dividend" Then r2.Interior.Color = vbYellow
Next i
End Sub
Now I'm trying to make cells negative or possitive based upon the value of r1. I tried this:
If r1.Value = "Verkoop" Then r2.Value = r2.Value * (-1)
Solution 1:[1]
Issue seems to be that r2 contains multiple cells hence below code will not work
If r1.Value = "Verkoop" Then r2.Value = r2.Value * (-1)
This needs to be changed to
If r1.Value = "Verkoop" Then
For Each c In r2.Cells
c.Value = c.Value * (-1)
Next
End if
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ibrez |
