VBA Macro for Format Numbers formatting Millions, Thousands and negative numbers based on cell value

drose1105

New Member
Joined
Mar 27, 2023
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am looking for a Macro that will format numbers to $m or $k based on the cell's value & if the cell is Negative, format text as Red with brackets.

I have 2 separate below Macros but i want the Macro logic to automatically determine if the number in the cell is in Millions or Thousands (probably some kind of IF, Then macro logic.

Below is the Result i want to achieve.

Number (before)Desired Result
2500000$2.5M
-2500000($2.5M)
825000$825K
-825000($825K)

Sub M_Format()
' $M Format
Selection.NumberFormat = "$0.0,,""M""; [Red] ($0.0,,""M)"""
End Sub
Sub K_Format()
' $K Format
Selection.NumberFormat = "$0,""K""; [Red]($0,""K)"""
End Sub
 

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.

Forum statistics

Threads
1,215,087
Messages
6,123,050
Members
449,092
Latest member
ikke

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