VBA decimal places

A

Alex

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
 
T

Tom Ogilvy

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

Alex

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top