Macro to find cells and flip signs

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,161
I have a report that kicks into excel that makes credit numbers show up as say "45.36CR" the debits come in as "45.36". I was hoping for a macro that could locate all cells in columns D:E with "CR" and delete the "CR" then flip the sign of the number to neg. So the outcome would be "(45.36)" Leave all other cells (debits) alone. Also, the amounts of the numbers will be varied, some in the 1000's, some 100's, ect.

Thank you very much for your time and help
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
How's this:
Code:
Sub FlipMe()
Dim a As Long
Dim Limit As Long
Limit = Cells(Rows.Count, 4).End(xlUp).Row
a = Cells(Rows.Count, 5).End(xlUp).Row
If Limit < a Then Limit = a
For a = 1 To Limit
    If Right(Cells(a, 4), 2) = "CR" Then
        Cells(a, 4) = Val(Left(Cells(a, 4), Len(Cells(a, 4)) - 2)) * -1
    End If
    If Right(Cells(a, 5), 2) = "CR" Then
        Cells(a, 5) = Val(Left(Cells(a, 5), Len(Cells(a, 5)) - 2)) * -1
    End If
Next a
End Sub
 

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,659
Office Version
  1. 2019
Platform
  1. Windows
Code:
Sub FlipSign()
For Each cl In Range("D:E")
    If Right(cl.Value, 2) = "CR" Then
        cl.Value = CDbl(Left(cl.Value, Len(cl.Value) - 2)) * (-1)
    End If
Next cl
End Sub
 

Forum statistics

Threads
1,181,055
Messages
5,927,858
Members
436,573
Latest member
CMR237

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top