PDA

View Full Version : Solved: Write number as string



Petrini
04-28-2010, 01:50 PM
How can I write a number as string in a cell?
I'm using php but it's actually the same thing..

For example, I have a variable set as "042810":

$date = "042810";

When I set the cell value:

$worksheet->Range($range)->Value = $date;

It looks like 42810.
If I use NumberFormat, it would only work as a mask, the value would remain 42810.
If I set it as "'042810" (with apostrophe at the star), it would look right but the actual value in the cell would still keep the apostrophe.
What should I do?
Thank you!

Aussiebear
04-28-2010, 02:00 PM
Format the cell as Text

Bob Phillips
04-29-2010, 01:26 AM
Dim myDate As String

myDate = "042810"

With ActiveSheet.Range("J1")

.NumberFormat = "@"
.Value2 = Format(myDate, Left$(String(10, "0"), Len(myDate)))
End With

Petrini
04-29-2010, 05:16 AM
Thank you!!