PDA

View Full Version : [SOLVED] Using If Then Else statement I think?



Tenspeed39355
08-14-2005, 06:20 AM
Good morning. I am using excel ss. I have a column that has both negative and positive numbers in the column. I would like to be able to put the negative numbers in column C and the positive numbers in column D, is there a way to accomplish this? There might be 15 numbers some of which are negative and some that are positive. There might be some blanks also.
Max:yes

mdmackillop
08-14-2005, 06:26 AM
You can use a simple If formula in each column
In C
=IF(A1<0,A1,"")
In D
=IF(A1>0,A1,"")
or are you looking for some code to move the numbers from the original column to the new columns? If so here is some basic code which works on a selection


Sub MoveIt()
For Each cel In Selection
Select Case cel
Case Is = ""
'Do nothing
Case Is > 0
Cells(cel.Row(), 3) = cel
cel.ClearContents
Case Is < 0
Cells(cel.Row(), 2) = cel
cel.ClearContents
Case Is = 0
Cells(cel.Row(), 3) = cel
cel.ClearContents
End Select
Next
End Sub

Tenspeed39355
08-15-2005, 05:17 AM
Good morning . The IF Statements work just fine. I see another problem. When I move the negative numbers over they have a minus sign in front of the numbers, is there any way when I move the negative number over to take the minus sign out. The formula that I have to use calls for the numbers to be positives. LOL
Max

Bob Phillips
08-15-2005, 08:19 AM
Good morning . The IF Statements work just fine. I see another problem. When I move the negative numbers over they have a minus sign in front of the numbers, is there any way when I move the negative number over to take the minus sign out. The formula that I have to use calls for the numbers to be positives. LOL
Max



Sub MoveIt()
For Each cel In Selection
Select Case cel
Case Is = ""
'Do nothing
Case Is >= 0
Cells(cel.Row(), 3) = cel
cel.ClearContents
Case Is < 0
Cells(cel.Row(), 2) = -cel
cel.ClearContents
End Select
Next
End Sub

mdmackillop
08-15-2005, 10:19 AM
If you just require the If formula,
In C
=IF(A1<0,-A1,"")