#1
|
|||
|
|||
Formatting a calculated number - to be added to bookmark
Hi,
I have a userform which requires to the user to enter the number of kilometers travelled. On the word document the number of kms shows but also the cost (i.e. $0.85/km) I've managed to do the code for this and it's working great. The only issue is that the amount that goes to the bookmarked place for the cost is showiong as 1 decimal place (It's $....). Can someone please help me with the code I need to format the cost amount correctly? Below is the code - it shows the number of Kms going to the bookmarked location for that in the document and the cost (once calculated) going to the bookmarked place for it. Dim KMsTravelled As Range Set NumberKMs = ActiveDocument.Bookmarks("NumberKms").Range NumberKMs.Text = Me.KMsTravelled.Value Dim KMsCost As Range Set KMsCost = ActiveDocument.Bookmarks("KMsCost").Range KMsCost.Text = Me.KMsTravelled.Value * 0.85 Thanks for your help |
#2
|
||||
|
||||
You could both simplifiy your code and achieve the desired result with:
Code:
With ActiveDocument .Bookmarks("NumberKms").Range.Text = Format(Me.KMsTravelled.Value, "#,##0") .Bookmarks("KMsCost").Range.Text = Format(Me.KMsTravelled.Value * 0.85, "$#,##0.00") End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Error received when I tried the code
Hi Paul,
When I tried the code I received an error. Se attached screenshot of error message and code. Not sure what I've done wrong. |
#4
|
||||
|
||||
Given the line on which the error occurs, it suggests the document you're working on lacks a bookmark named 'KMsCost'.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thanks Paul
Not sure how I missed that |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
With macro/userform to replace bookmark only works with number | TheBigBoss | Word VBA | 2 | 03-27-2022 10:26 PM |
Can I use a variable to display the page number of a bookmark ? | delboy | Word | 3 | 12-29-2020 01:16 PM |
I don't understand new formatting marks word has spontaneously added to my document | RichardJ | Word | 5 | 07-30-2020 11:04 AM |
how to get Word to automatically re-number the headings when a new on is added | lauped | Word | 3 | 07-13-2019 10:32 AM |
Add external hyperlink to a calculated number | Harleygal17 | Excel | 4 | 04-06-2017 11:38 PM |