Rita has attended:
O365 Digital Champions course
O365 Intermediate training PM course
PowerPoint Intermediate Advanced course
Presenting a number that is copied from Excel to Word
I'm trying to copy some numbers from an Excel table to a Word table using a Macro in Excel. One of the numbers is 0.020 but when it's copied it is rounded to 0.02. How can I present the number as 0.020?
Thanks.
RE: Presenting a number that is copied from Excel to Word
Hi Rita,
Thank you for the forum question.
I hope the 3 days of Excel where useful and thank you for the nice feedback.
Have a look at the code below. I have just added the Format function in two lines. Otherwise it is exactly the same code as we did yesterday.
Sub CreateCert()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim tblTable As Word.Table
Dim iCounter As Integer
Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.Open("C:\Users\jens\Desktop\Excel for scientist\Certificat.dot")
Set tblTable = wDoc.Tables(1)
With wDoc
For iCounter = 1 To 4
tblTable.Cell(2, 1 + iCounter).Range.Text = Format(Round(Cells(17, 2 + iCounter).Value, 3), "0.000")
tblTable.Cell(3, 1 + iCounter).Range.Text = Format(Round(Cells(23, 2 + iCounter).Value, 3), "0.000")
Next iCounter
.SaveAs2 Filename:=("C:\Users\jens\Desktop\Excel for scientist\test2.docx"), _
FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False
.Close
End With
wApp.Quit
End Sub
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector