Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel NumberFormat Property

Status
Not open for further replies.

DwaineC

MIS
Jan 6, 2003
40
0
0
US
Geez, this should be simple. I specifically want to format a range of cells as text. When I set the Numberformat property of a range to "Text", I get an error that states I should choose one of the options available. Well, duh, "Text" is an option from within excel. It only allows me to specify "General", which is the cause of the issue (dropping leading zeroes upon save).

Dim App As Application = New Application
Dim WBs As Workbooks = App.Workbooks
Dim WB As Workbook = WBs.Add()
Dim STs As Sheets = WB.Worksheets
Dim WS As Worksheet = STs(1)

Dim FR As Range = WS.Range("A1").EntireColumn
FR.HorizontalAlignment = Excel.Constants.xlLeft
FR.NumberFormat = "Text"

Here's my error:

Run-time exception thrown : System.Runtime.InteropServices.COMException - Microsoft Excel cannot use the number format you typed.

Try using one of the built-in number formats. On the Format menu, click Cells, and then click the Number tab. Select the category you want, and then choose other options.

For more information about custom number formats, click Help.

This application will be deployed internationally and I really don't want to have to instruct the users to change the format manually, because you know they'll forget and there's too much at stake to be dropping leading zeroes.

BTW, I can do Range.Numberformat = "0000" which takes care of rows that I am creating. But the user will be adding new rows, and that's the problem.



 
No need to reply... It is the "@" sign to to programmatically format an excel range: Range.Numberformat = "@".

Absolutely no documentation anywhere for that. They let you type "General", but choose a stupid symbol for other formats. Give me a break!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top