Consulting

Results 1 to 4 of 4

Thread: Solved: Write number as string

  1. #1

    Solved: Write number as string

    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!

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Format the cell as Text
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim myDate As String

    myDate = "042810"

    With ActiveSheet.Range("J1")

    .NumberFormat = "@"
    .Value2 = Format(myDate, Left$(String(10, "0"), Len(myDate)))
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thank you!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •