Thread: Number Format
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Aaron Aaron is offline
external usenet poster
 
Posts: 59
Default Number Format

I have this macro code:


Range("u22:u26").NumberFormat = _
Range("ad22").NumberFormat '(number format in ad22 is "0.00")

Dim KeyCell As Range, AnswerCell As Range
Dim DP As Long
Dim kcFmt As String
Dim acFmt As String

Set KeyCell = [q16]
Set AnswerCell = [u22:u26] 'set + - sign to cells

'Get DP from Key Cell
kcFmt = KeyCell.NumberFormat

DP = Len(kcFmt) - InStr(1, kcFmt, ".") + 0 'add a number here to apply
more DP

'Add one decimal place to the KeyCell number format
acFmt = "0." & Application.WorksheetFunction.Rept("0", DP)

'special case of kcFmt is "0"
If kcFmt = "0" Then acFmt = "0.0"

acFmt = "+" & acFmt & ";-" & acFmt & ";0"

'Assign new format to answer cell
AnswerCell.NumberFormat = acFmt


If I rem out the first 2 lines with a ' it works and places a + or -
where it should, but if I perform the first 2 lines just before that
first, it doesent apply the + or -.

How can I make the two work together so it does +0.00 or -0.00?

TIA,

Aaron.