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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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