Results 1 to 2 of 2
  1. #1
    Bronze Lounger
    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.

  2. #2
    5 Star Lounger
    Join Date
    Jan 2004
    Thanked 129 Times in 113 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts