If then else problem

L

Legal Learning

I think I originally posted this in the wrong category and now realize this
has to be a vba macro situaion. AHHH! This means trouble for me. :)

Here is what I need:

If the any cell in column C has text, then the numeric values in column D
must be negatives. They are currently all postive numbers now. There are
many fields that do not have any text in column C and those numbers must
remain postivie numbers.

Any help is greatly, greatly appreciated.
 
D

Don Guillett

I answered your OTHER version of this question. Just modify to put into a
loop

Right click sheet tab>view code>insert this.

Private Sub Worksheet_Change(ByVal Target As Range)
'On Error Resume Next
If Target.Address <> Range("c3").Address Then Exit Sub
If Not IsNumeric(Target) Then
If IsNumeric(Target.Offset(1)) Then
Target.Offset(1) = -Abs(Target.Offset(1))
End If
End If
End Sub
=========
For your CURRENT question

Sub loopchgvaluetoneg()
For Each c In Range("c12:c15")
If Not IsNumeric(c) Then
If IsNumeric(c.Offset(, 1)) Then
c.Offset(, 1) = -Abs(c.Offset(, 1))
End If
End If
Next c
End Sub
 
J

JBeaucaire

Try this:

==========
Sub TextEqualNegative()
Dim cell As Range, RNG As Range
Set RNG = Columns("B:B").SpecialCells(xlCellTypeConstants, 2)

For Each cell In RNG
Range("C" & cell.Row).Value = -Abs(Range("C" & cell.Row).Value)
Next cell

End Sub
==========

Does that work for you?
 
S

Sam Wilson

If you want to use formulas, put this in column E:

=IF(ISTEXT(C1),-ABS(D1),ABS(D1))

copy it down, then copy the range paste special/values over the equivalent
range in D. A macro is better if this isn't a one-off process though.

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top