Format Number in Header

deep6

Board Regular
Joined
Apr 20, 2004
Messages
55
Hi,

I've got a RightHeader that is referencing a number from a cell. However, sometimes that figure has 12 numbers to the right of the decimal. Is there some code that I can use that will format the number in the header so that it only goes 2 decimal places?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Untested, but can you use the Format command when assigning the value from the cell to the header ?

ie:

Label1.Caption = Format(Cells(4, 3).Value, "#.###") for 3 decimal places
 
Upvote 0
Code:
Sub RtHdr()
'assumes your number for header is in range a1
'good luck, Chas Weber
    myHeader = Format(Range("a1"), "00.00")
    ActiveSheet.PageSetup.RightHeader = myHeader
End Sub

Chas
 
Upvote 0
Yes I can! Only I didn't know that until you suggested it. Thank you for your help ... problem solved.
 
Upvote 0
Thank you too, Chas17. I just saw your post and it too works. I'm not real good a using code to do formatting, but both of you have given me some insight.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,216,483
Messages
6,130,932
Members
449,607
Latest member
babylegs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top