View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
John Green[_4_] John Green[_4_] is offline
external usenet poster
 
Posts: 47
Default Setting number format on range of cells

What you are doing is setting the Style number format, not the Cell number
format.

By default, all the cells in the workbook will have the Normal style. By
changing the Normal style, you affect all the cells in the workbook.

Remove the .Style from your code and you will be setting the cell formats.

By the way, your code depends on the worksheet you are changing being
active. If you want to have it work on other sheets, you would need to
qualify the Range reference and each Cells reference with the name of the
worksheet (and the workbook if the workbook is not selected). Thecode is
fine if it only works on an active sheet.

--
John Green
Sydney
Australia


"Neils Christoffersen" wrote
in message ...
I have the following VBScript function to set the NumberFormat on a Range.
It appears instead to be setting the NumberFormat for all cells in the

Sheet.
Can anyone explain what I'm doing wrong? (Using Excell 2002)

Private Sub setCellRangeNumberFormat (intBeginRow, intBeginColumn,
intEndRow, intEndColumn, strNumberFormat)
m_objExcelApp.Range ( _
m_objExcelApp.Cells(intBeginRow, intBeginColumn), _
m_objExcelApp.Cells(intEndRow, intEndColumn) _
).Style.NumberFormat = strNumberFormat
End Sub

Thanks!