Setting number format on range of cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
Depends on how you are calling this function (what arguments you are
supplying)...
 
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.
 

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

Back
Top