![]() |
Setting number format on range of cells
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! |
Setting number format on range of cells
Depends on how you are calling this function (what arguments you are
supplying)... "Neils Christoffersen" wrote: 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! |
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! |
All times are GMT +1. The time now is 10:42 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com