Results 1 to 2 of 2
Thread: Change signs based on criteria
2013-02-04, 09:30 #1
- Join Date
- Jan 2001
- Thanked 0 Times in 0 Posts
Change signs based on criteria
In column A I have >100 rows with each cell containing an "R" or a "D". In column B I have correnspoding numerical data (all non-negative). What I would like is vba that would put a minus sign in each of the cells in column B when there is a corresponding "D" in column A, but leave the cells in column B alone when the corresponding cell in column A is an "R". Any ideas?
Thanks in advence.
2013-02-04, 10:01 #2
- Join Date
- Jan 2004
- Thanked 105 Times in 90 Posts
1. As per your earlier request, I have assumed that you want this procedure to operate on whatever cells you have selected in Column A.
2. I have assumed that the cells in Column B contain numbers.
3. I presume that you want to "negative" the values in Column B ? Just putting a negative sign in front will produce a curious outcome if the number is already negative.
If that's all OK then this code will do the trick:
Sub Negatives() For Each Sample In Selection.Cells If Sample.Value = "D" Then Sample.Offset(0, 1).Value = -Sample.Offset(0, 1).Value Next Sample End Sub