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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel .NumberFormat not working

Status
Not open for further replies.

bcoats

Programmer
Jun 20, 2001
49
0
0
US
I am using reference to Excel 10.0 library.

code xlSheet.Range("A2").NumberFormat = "#,##0.00" does not change the formatting of the cell. I had expected it to change it to a custom format but it did not. 4 still displayed as 4, not 4.00. Actually what I am needing is to set to Number with 2 decimals.

Another one I am trying is to set the dell to date type.

Any help would be appreciated.

Brian
 
Try selecting the cell first:

xlSheet.Range("A2").Select
Selection.NumberFormat = "#,##0.00"

I hope this helps.

Ron
 
Brian,
I had the same kind of problem with dates.
If the values are already written in the column, changing the numberformat will not change a thing.
This is what I had to do :

Change the numberformat to the one you need.

ExcelWST.Range("Z1") = 1 'Z1 is an empty cell
ExcelWST.Range("Z1").Select
ExcelApp.CutCopyMode = False
ExcelApp.Selection.Copy
for MyRow=1 to LastRow
ExcelWST.Cells(myRow, MyCol).Select
ExcelApp.Selection.PasteSpecial Paste:=xlValues, Operation:=xlMultiply, SkipBlanks _
:=False, Transpose:=False
Next MyRow
ExcelWST.Range("Z1") = ""


(Someone in this forum gave me the hint - couldn't find it again - sorry).
You can try it "manually" first.
Change the format of your row.
Type 1 in an empty cell.
Copy it.
Select the cell you like to change the format.
And do a "paste special", select value, multiply.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top