VBA Code to Convert Number Formats

JMC57

Board Regular
Joined
Apr 24, 2012
Messages
118
I need to create a VBA code that will accomplish the following in a specific Col

Example
904020161 to XXXXX-XXXX-XX where zeros fill in to create 00904-0012-24
88904020161 to XXXXX-XXXX-XX or 88904-0012-24

 

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.
I need to create a VBA code that will accomplish the following in a specific Col

Example
904020161 to XXXXX-XXXX-XX where zeros fill in to create 00904-0012-24
88904020161 to XXXXX-XXXX-XX or 88904-0012-24

You want the ending to always be 0012-24???
 
Upvote 0
No the numbers will be different. In one SS format will be 904001224 the other will be 00904-0012-24. Sorry I see the typo that made it confusing. I am comapring two reports where the number fomats for are different. If the first two numbers in one are zero the number is truncated form the report.
 
Upvote 0
To end the confusion, it would have been helpful if you posted the corrected numbers. Guessing from what you did post, I think you may be looking for this...

Code:
FormattedNumberInA1 = Format(Range("A1").Value, "00000-0000-00")
 
Upvote 0
I tried the faolling and it worked.

Thanks for your help- It did give me some ideas

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Columns("B").NumberFormat = "00000-0000-00"
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,156
Messages
6,129,188
Members
449,492
Latest member
steveg127

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