Share via

Word Input answer VBA

Anonymous
2024-09-02T21:27:17+00:00

Hello from Steve

Using word.

Objective Type in answer using VBA

I type in $62.95 $2.90 =

Is it possible please for it to type in the answer in this case $65.85 as shown below.

$62.95 $2.90 = $65.85

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2024-09-02T22:21:06+00:00

Select the text such as $62.95 $2.90 =, then run this macro:

Sub Compute()
    Dim txt As String
    Dim arr() As String
    Dim i As Long
    Dim sum As Double
    On Error GoTo ErrHandler
    txt = Replace(Selection.Text, "$", "")
    arr = Split(txt)
    For i = 0 To UBound(arr) - 1
        sum = sum + arr(i)
    Next i
    Selection.InsertAfter Format(sum, " $#,##0.00")
    Exit Sub
ErrHandler:
    MsgBox "Something went wrong!", vbExclamation
End Sub

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-09-02T22:32:01+00:00

    Hello HansV

    Brilliant

    I thank you

    All the Best

    Steve

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-09-02T21:45:07+00:00

    Hello HansV

    In the Word Document please.

    All the Best

    Steve

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2024-09-02T21:39:08+00:00

    Where do you enter this? In a document? In VBA InputBox? In a text box on a userform?

    Was this answer helpful?

    0 comments No comments