Search code examples
excelvbanumber-formatting

VBA Formatting to accounting format


I'm trying to get VBA to format a cell in the "accounting" format (in Euro). I have copied the format from the options which shows

_-* #.##0,00 €_-;-* #.##0,00 €_-;_-* "-"?? €_-;_-@_-

When I try to apply this to

.Cells(1, 1).NumberFormat = "_-* #.##0,00 €_-;-* #.##0,00 €_-;_-* " - "?? €_-;_-@_-" 

I get a 400 error. What am I doing wrong?


Solution

  • Double-up those double quotes (inside a string variable):

    Sub kjdsffh()
        With ActiveSheet
            s = "_-* #.##0,00 €_-;-* #.##0,00 €_-;_-* ""-""?? €_-;_-@_-"
            .Cells(1, 1).NumberFormat = s
        End With
    End Sub
    

    enter image description here