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?
 

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Fat Cat

Active Member
Joined
Nov 5, 2004
Messages
336
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
 

Chas17

Well-known Member
Joined
Oct 16, 2002
Messages
657
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
 

deep6

Board Regular
Joined
Apr 20, 2004
Messages
55
Yes I can! Only I didn't know that until you suggested it. Thank you for your help ... problem solved.
 

deep6

Board Regular
Joined
Apr 20, 2004
Messages
55
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,057
Messages
5,569,954
Members
412,300
Latest member
Chaneycr
Top