Obtaining the equivalent to printf or String.Format in Excel

No, but you can create a naive one simply enough by adding the following to a VBA module:

Public Function printf(ByVal mask As String, ParamArray tokens()) As String
    Dim i As Long
    For i = 0 To ubound(tokens)
        mask = replace$(mask, "{" & i & "}", tokens(i))
    Next
    printf = mask
End Function

=printf("Some text '{0}', more text: '{1}'", A1, A2)

Leave a Comment