Modify Macro Excel 2007 to change negative values to zero.

I have this lovely piece of code. It runs a paste special-->subtract. What I want is to add to that. If the pasted value is less than zero, I want it to be zero.

Sub SubtractWellsNameSets()
' Subtract Wells & Rename choice sets

If Range("c3") = "" Then
MsgBox "All liquors must have a price, even if it is 0.00"
Exit Sub
End If
If Range("a3") = "" Then
MsgBox "You must first paste all your liquors in the worksheet."
Exit Sub
End If
    Range(Selection, Selection.End(xlDown)).Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlSubtract, _
        SkipBlanks:=False, Transpose:=False
'Here is where I want to make any values less than zero to be zero.

Range(ActiveCell, ActiveCell.End(xlDown)).Select
    For Each cell In Selection
        cell.Value = cell.Value & ": Sub"
    Next cell
    Range(Selection, Selection.End(xlDown)).Copy

    Range("M" & Rows.Count).End(xlUp).Offset(1).Select
    Range(Selection, Selection.End(xlDown)).Copy
'This needs to be the first blank cell in column E instead of E87
    Range("E" & Rows.Count).End(xlUp).Offset(1).Select
'Here, I am removing duplicates in column A
   Range(Selection, Selection.End(xlDown)).RemoveDuplicates Columns:=1, Header:=xlNo
    Range(Selection, Selection.End(xlDown)).Copy
    Range("A" & Rows.Count).End(xlUp).Offset(1).Select
    Call ResetCondFormatsChoiceSets
End Sub

Open in new window

I can email a workbook to anyone who would like it, but cannot load here.
LVL 22
Anne TroyEast Coast ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls try

For Each cell In Selection
    cell.Value = Application.max(0, cell.Value)

Open in new window

ProfessorJimJamMicrosoft Excel ExpertCommented:
you can call the sub below from the above sub

Sub negativetozero()

Dim RowNum as Long, ColNum as Long

Application.ScreenUpdating = False

For ColNum = 1 to Cells(1, Columns.Count).End(xlToLeft).Column
  For RowNum = 2 to Cells(Rows.Count, ColNum).End(xlUp).Row
     If Val(CStr(Cells(RowNum, ColNum))) < 0 Then cells(RowNum, ColNum) = 0
  Next RowNum 
Next ColNum

Application.ScreenUpdating = True

End Sub

Open in new window

Rory ArchibaldCommented:
You could add:
Selection.Replace "-*", 0, xlWhole

Open in new window

just after the PasteSpecial operation.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ProfessorJimJamMicrosoft Excel ExpertCommented:
the code, i provided works nice converts all negative values to zero, assuming that your data starts from column A and it will work on each subsequent column to the right untill the last column with data.

change the For ColNum = 1  to other numbers if your first column is not A,  column B is 2 and C3 and so on.
Anne TroyEast Coast ManagerAuthor Commented:
So simple, Rory!!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.