Macro to format data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,601
Office Version
  1. 2021
Platform
  1. Windows
I have the folowing values thast have been imported in Col J. I need a macro that will format these values as #,##0.00;(#,##0.00) for eg if the values appears as 4.384,21 it must be formatted as 4,384.24 and not 4.384,21. Negaitives appearing as 2.384,34- should be formatted as (2,384.34) and not 2.384.34

Your assistance will be most appreciated


420110 92030.xls
JKLM
164.384,2197
172.384,34-97
181.457,3825-
1931,4025-
202.140,0925-
216.450,8425-
222.228,0825-
23846,4525-
24164,7925-
2577,5225-
2612.323,7425-
278.892,0025-
282.772,7125-
Page 1
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Scrapped my post - I totally misinterpreted your number format needs... brb.
 
Last edited:
Upvote 0
Updated now.

Code:
Sub NumberFormat()
For Each c In Selection
    c.Value = WorksheetFunction.Substitute(c.Value, ",", "(DEC)")
    c.Value = WorksheetFunction.Substitute(c.Value, ".", ",")
    c.Value = WorksheetFunction.Substitute(c.Value, "(DEC)", ".")
    
    If Right(c.Value, 1) = "-" Then
        c.Value = Left(c.Value, Len(c.Value) - 1)
        c.Value = c.Value * -1
    End If
    
    c.Value = c.Value + 0
    c.NumberFormat = "#,##0.00;(#,##0.00)"
    
Next
    
End Sub
 
Upvote 0
Thanks for the reply and your help, much appreciated
 
Upvote 0
Is there any way to amend the Macro so that if the number format in Col M4 to the last row in Col M is in the correct format to exit the macro, otherwise to execute the macro?

If so, please amend the macro.

Your assistance in this regard will be most appreciated
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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
Back
Top