VBA decimal places

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear Excel Helper

In an Excel workbook I have a worksheet and a chart.

In the worksheet in cell P1 I have worked out a value as a percentage. I
have this displayed on my chart by using the folowing within my VBA code...

ActiveChart.Shapes("Text Box 13").Select
Selection.Characters.Text = Sheets("ComboBoxRef").Range("$P$1")

Now, the problem is as follows. On my worksheet, cell P1 is formatted to
display just two decimal places i.e. it displays as 6.3. However, on my chart
it displays as 6.32203200179032. How can I get it displayed as two decimal
places on my chart?

I have tried formatting the cell P1 but it makes no difference regaring what
is displayed. It is as if VBA only displays the 'underlying' value. I have
messed about with...

application.worksheetfunction.fixed(P1,2)

and...

numberformat= "0.0"

but it seems unsatisfactory.

If there is an easy way around this please let me know.

Best Regards

Alex
 
ActiveChart.Shapes("Text Box 13").Select
Selection.Characters.Text = _
Sheets("ComboBoxRef").Range("$P$1"),Text
 
Tom

Thanks for that help. It works well.

Alex

Tom Ogilvy said:
ActiveChart.Shapes("Text Box 13").Select
Selection.Characters.Text = _
Sheets("ComboBoxRef").Range("$P$1"),Text
 
Back
Top