prepend data to existing excel worksheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • y0sh1
    New Member
    • Sep 2006
    • 1

    prepend data to existing excel worksheet

    I'm new at using macros in excel and need to prepend zeros to a column of data. i know i'll need an if statement with some kind of loop.
    the logic goes something like, select cell, if number is less than 9 digits long prepend "0" until it is equal to 9 digits. if equal to 9 digits do nothing and select next.
    can anyone give me some idea as to how the syntax would look like? any help is much appreciated.
  • KenMacksey
    New Member
    • Sep 2006
    • 6

    #2
    Originally posted by y0sh1
    I'm new at using macros in excel and need to prepend zeros to a column of data. i know i'll need an if statement with some kind of loop.
    the logic goes something like, select cell, if number is less than 9 digits long prepend "0" until it is equal to 9 digits. if equal to 9 digits do nothing and select next.
    can anyone give me some idea as to how the syntax would look like? any help is much appreciated.

    Are the numbers entered as text, like a phone # or are they numeric?

    If they are text, format the cells as text and use something like this.

    for i = 1 to 10

    if len(Range("A" & i)) < 9 then
    Range("A" & i) = "0" & Range("A" & i)
    end if

    next i


    HTH

    Ken

    Comment

    Working...