P
Pete
I have created this excel VBA function to center a string.
It works but is there a better way?
Sub Test()
MsgBox CenterString("Center This String", 50)
End Sub
Function CenterString(xInput As String, xLength As Long)
xM = Space(((xLength / 2) - (Len(xInput) / 2) + 1)) + xInput
CenterString = xM + Space(xLength - Len(xM))
End Function
It works but is there a better way?
Sub Test()
MsgBox CenterString("Center This String", 50)
End Sub
Function CenterString(xInput As String, xLength As Long)
xM = Space(((xLength / 2) - (Len(xInput) / 2) + 1)) + xInput
CenterString = xM + Space(xLength - Len(xM))
End Function