Accounting formatting

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I have 9 columns that I want in accounting format in vba. Is there an efficient way to format numbers in accounting without writing another line of code like below? Or maybe reference the accounting format and apply the reference to the one line?

VBA Code:
    Range("H" & LRow) = tbOPrice.Value
    Range("H" & LRow).NumberFormat = "_($*#,##0.00_);_($*(#,##0.00);_($*""_""??_);_(@_)"

I tried this but doesn't work.
VBA Code:
Format(Range("H" & LRow) = tbOPrice.Value,  "_($*#,##0.00_);_($*(#,##0.00);_($*""_""??_);_(@_)")
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
ONE line is used to attribute value
ONE line is used to attribute number format string

Use a loop to format cells in multiple columns at once
VBA Code:
Dim col As Variant
For Each col In Array("H", "L", "T", "Q")
    Range(col & Lrow).NumberFormat = "_($*#,##0.00_);_($*(#,##0.00);_($*""_""??_);_(@_)"
Next col
 
Last edited:
Upvote 0
or use the UNION function
VBA Code:
Union(Range("H" & LRow), Range("L" & LRow), Range("T" & LRow), Range("Q" & LRow)).NumberFormat = "_($*#,##0.00_);_($*(#,##0.00);_($*""_""??_);_(@_)"

To number format adjacent columns (here H:M) ...
VBA Code:
Range("H" & LRow).Resize(, 6 ).NumberFormat = "_($*#,##0.00_);_($*(#,##0.00);_($*""_""??_);_(@_)"
 
Upvote 0
this is what I tried to did, but it didn't work out

VBA Code:
    For Each col In Array("D", "H:J", "M:N", "O:P")
        Range(col & LRow).NumberFormat = "_($*#,##0.00_);_($*(#,##0.00);_($*""_""??_);_(@_)"
    Next col
 
Upvote 0
Stop being lazy ;)
List each column letter separated by a comma
 
Upvote 0
Here is another option for you

VBA Code:
    For Each col In Split("D H I J M N O P")
        Range(col & LRow).NumberFormat = "_($*#,##0.00_);_($*(#,##0.00);_($*""_""??_);_(@_)"
    Next col
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,170
Members
448,870
Latest member
max_pedreira

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