Conditional formatting

[Closed]
Report
-
Posts
1942
Registration date
Monday August 16, 2010
Status
Contributor
Last seen
September 2, 2021
-
Hello,

Can I use conditional formatting to change a number from positive to negative based on the text in another cell? For example, I have a file with column A has either Buy or Sell in each cell and column B has the amount bought or sold, which is always a positive number. I'd like a formula that would change the number in column B to a negative if the cell next to it says 'Sell' and leave alone (positive) if it says 'Buy'. Is there a way to do this?

1 reply

Posts
1942
Registration date
Monday August 16, 2010
Status
Contributor
Last seen
September 2, 2021
145
Steve, Good afternoon.

Try to use:

Sub ChangeToNegative()
 For i = 1 To 1500
   If Range("A" & i).Value = "Sell" Then
      Range("B" & i).Value = Range("B" & i).Value * -1
   End If
 Next
End Sub

Adapt the value 1500 to your reality.

Is this what you want?
I hope it helps.