+ Reply to Thread
Results 1 to 8 of 8

Formatting a integer variable or something...

  1. #1
    Registered User
    Join Date
    01-22-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    13

    Formatting a integer variable or something...

    I'm trying to format a number inside of a chain of a string. So,

    Worksheets("TASK").Cells(task_sht_current_row, task_sht_act_id_column) = Cells(current_act_row, work_package_column) & "-" & Cells(current_act_row, cti_wp_column) & "-" & current_act_step_num

    So I'm trying to format the last variable so that it is always four digits, ie, 0001, 0034, 0204, 1234, etc...

    Any clue how to do this, I've searched around and can't seem to find the code for it. I could do it with a long set of conditional statements, but I'm pretty sure there is a format function or something. Thank you.

  2. #2
    Registered User
    Join Date
    05-02-2004
    MS-Off Ver
    2007
    Posts
    43
    Use Format(current_act_step_num,"0000")

    TJ

  3. #3
    Registered User
    Join Date
    01-22-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    13

    ...

    So I put that line in,

    ... = Cells(current_act_row, work_package_column) & "-" & Cells(current_act_row, cti_wp_column) & "-" & Format(current_act_step_number, "0000")

    And I'm not getting any errors, but that part of the chain isn't showing up. at all.

    DR0411-TK00-

    Where is should be,

    DR0411-TK00-XXXX

  4. #4
    Registered User
    Join Date
    05-02-2004
    MS-Off Ver
    2007
    Posts
    43
    I can only get that if the variable is declared as Variant and is empty.

    How have you declared current_act_step_number and are you sure it has a value?

    TJ

  5. #5
    Registered User
    Join Date
    01-22-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    13
    Yes,

    I declare is outside the sub, and set it to

    Please Login or Register  to view this content.
    then later on inside the sub

    current_act_step_num = 10

    But later on there is a loop for generating the step numbers.

    Please Login or Register  to view this content.
    Last edited by timbreeding; 01-22-2009 at 11:33 AM. Reason: Code Tags

  6. #6
    Registered User
    Join Date
    01-22-2009
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    13
    Nevermind,

    I had a typo.

    num vs. number

  7. #7
    Registered User
    Join Date
    05-02-2004
    MS-Off Ver
    2007
    Posts
    43
    Option Explicit


  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    timbreeding, please take a few minutes to read the forum rules, then edit your post to add code tags.

    Edit: Thank you.
    Last edited by shg; 01-22-2009 at 04:21 PM.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1