How to change negative numbers into positive if the puse f

davekim1000

New Member
Joined
Feb 11, 2005
Messages
4
Can someone help me create a macro that will change a number value into a negative if an identifier for that number falls within a range of identifiers that indicate the number needs to be negative?

Example:

A1 B1
1234 blue
2352 red
4569 green
7452 yellow

if the identifier is red or yellow...then the value in the same row as that identifier should be negative.

A1 B1
1234 blue
-2352 red
4569 green
-7452 yellow

thanks in advance for your help

david
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Private Sub CommandButton1_Click()

Dim r As Range

For Each r In Range("A1", Range("A65535").End(xlUp))
If r.Offset(0, 1).Value = "red" Or r.Offset(0, 1).Value = "yellow" Then
r.Value = r.Value * -1
End If
Next
End Sub


HTH
Cal
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top