VBA need to format of Accounting

mduntley

Board Regular
Joined
May 23, 2015
Messages
79
Office Version
  1. 365
  2. 2016
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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
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
 

mduntley

Board Regular
Joined
May 23, 2015
Messages
79
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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:

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
How did you get it to work?
 

mduntley

Board Regular
Joined
May 23, 2015
Messages
79
Office Version
  1. 365
  2. 2016
Platform
  1. Windows

ADVERTISEMENT

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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
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?
 

mduntley

Board Regular
Joined
May 23, 2015
Messages
79
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Forum statistics

Threads
1,136,339
Messages
5,675,199
Members
419,553
Latest member
hanahass

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
Top