Trouble with this code

G

Guest

I'm using this macro to force the cells to a negative value. The only thing
is I only need it to force a negative value if there is data in the cell.
This code is filling the empty cells with a value of $ 0.00. I need those
cells to remain empty but just not sure how to alter the code to do that.
Any help you can give is very much appreciated. Thank you


Sub ForceCellsToNegative()

Dim Rng As Range
Dim rCell As Range

Set Rng =
Range("B85:B86,G20:G31,G33:G44,G46:G57,G82,G85:G86,B91,G7:G8,G77:G79,G83,G89:G90")

For Each rCell In Rng.Cells
With rCell
..Value = -Abs(.Value)
..Font.Name = "Arial"
..Font.Bold = True
..NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

If Not Rng Is Nothing Then

Else
Exit Sub
End If

End With
Next rCell

End Sub
 
G

Guest

Sub ForceCellsToNegative()

Dim Rng As Range
Dim rCell As Range

Set Rng =
Range("B85:B86,G20:G31,G33:G44,G46:G57,G82,G85:G86,B91,G7:G8,G77:G79,G83,G89:G90")

For Each rCell In Rng.Cells
With rCell
if .Value <> "" then
..Value = -Abs(.Value)
..Font.Name = "Arial"
..Font.Bold = True
..NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
end if
If Not Rng Is Nothing Then

Else
Exit Sub
End If

End With
Next rCell

End Sub
 
N

Norman Jones

Hi Jouioui,

Why are you opening a new thread?

Perhaps try:
'=============>>
Public Sub ForceCellsToNegative()
Dim Rng As Range
Dim rCell As Range

Set Rng = Range("B85:B86,G20:G31,G33:G44,G46:G57," _
& "G82 , G85: G86 , B91, G7: G8 ," _
& "G77: G79 , G83, G89: G90 ")

For Each rCell In Rng.Cells
With rCell
If Not IsEmpty(.Value) Then
.Value = -Abs(.Value)
End If

.Font.Name = "Arial"
.Font.Bold = True
.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End With
Next rCell

End Sub
'<<=============
 

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

Similar Threads


Top