VBA need to format of Accounting

mduntley

Board Regular
Joined
May 23, 2015
Messages
139
Office Version
  1. 365
Platform
  1. Windows
I found this code to make it so a cell with multi lines to easy be the format, but I am trying to incorporate to view it as accounting as the other cell that has single lines that have accounting format. I tried to do it as formatcurrency but it does not look the ones below or above. Can this be done?


Code:
Public Function FORMATLINES(cell As Range) As StringDim data() As String, i As Long
data = Split(cell.Text, vbLf)
For i = 0 To UBound(data)
    If IsNumeric(data(i)) Then data(i) = FormatNumber(data(i), 2, vbTrue, vbFalse, vbTrue)
Next
FORMATLINES = Join(data, vbLf)
End Function
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try using Format instead of FormatNumber.
Code:
Public Function FORMATLINES(cell As Range) As StringDim data() As String, i As Long
    data = Split(cell.Text, vbLf)
    For i = 0 To UBound(data)
        If IsNumeric(data(i)) Then data(i) = Format(data(i), "Currency")
    Next
    FORMATLINES = Join(data, vbLf)
End Function
 
Upvote 0
got it to work, but my chart isnt in accounting form. it has this

[TABLE="width: 500"]
<tbody>[TR]
[TD]$ 5.00[/TD]
[/TR]
[TR]
[TD] $4.00
$3.00[/TD]
[/TR]
[TR]
[TD]$ 7.00[/TD]
[/TR]
</tbody>[/TABLE]


I want to see it as this

[TABLE="width: 500"]
<tbody>[TR]
[TD]$ 5.00[/TD]
[/TR]
[TR]
[TD]$ 4.00
$ 3.00[/TD]
[/TR]
[TR]
[TD]$ 7.00[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
I got the vba to work because it was this:

Rich (BB code):
Public Function FORMATLINES(cell As Range) As StringDim data() As String, i As Long


When it needs to be
Rich (BB code):
Rich (BB code):
Public Function FORMATLINES(cell As Range) As String
Dim data() As String, i As Long
 
Upvote 0
I assumed that was a typo I've seen similar things happen when code is copied to a post.

Once you fixed that did you try my suggestion of using Format instead of FormatNumber?
 
Upvote 0
I assumed that was a typo I've seen similar things happen when code is copied to a post.

Once you fixed that did you try my suggestion of using Format instead of FormatNumber?


yes, i got it to work, thanks
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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