View Single Post
 
Old 03-12-2021, 01:21 PM
jeffreybrown jeffreybrown is offline Windows 10 Office 2016
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default VBA insert quick part formula and format as percentage

It seems I've looked everywhere, but can't seem to find the right way to format a quick part formula as percentage. Here is what I've tried.

Code:
Sub test()
    With ActiveDocument.Tables(1)
        .Cell(5, 5).Formula Formula:="=A2/B2*100"
        .Cell(5, 5).Range.Text = Format(.Cell(5, 5), "0.00%")
    End With
End Sub
I used the macro recorder and came up with the below, works fine, but of course it makes me select the table cell first.

Code:
Sub Macro3()
    Selection.InsertFormula Formula:="=A2/B2*100", NumberFormat:="0.00%"
End Sub
Reply With Quote