VBA need to format of Accounting

mduntley

Board Regular
Joined
May 23, 2015
Messages
134
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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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

$ 5.00
$4.00
$3.00
$ 7.00

<tbody>
</tbody>


I want to see it as this

$ 5.00
$ 4.00
$ 3.00
$ 7.00

<tbody>
</tbody>
 
Last edited:
Upvote 0
How did you get it to work?
 
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,214,875
Messages
6,122,046
Members
449,063
Latest member
ak94

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