Word Loop macro

  • I have a word macro that formats a list of numbers. Essentially, it takes a column of numbers and formats them like: 4596845, 4555454, 8975545, ...


    I need the macro to loop until the end of the column of numbers. However, right now it won't stop looping. I am new to this so please be patient. :)


    This is the code I have now:


    Sub ReFormat()
    '
    ' ReFormat Macro
    ' Macro recorded 2/23/2006'
    Do
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=", "
    Selection.MoveRight Unit:=wdCharacter, Count:=8

    Loop


    End Sub


    How do I make it detect the end of the number list??


    Thank you!

  • Re: Word Loop macro


    Not sure where your assigning a value to wdCharacter or what is it exactly, but this should help.


    Code
    If wdCharacter = "" Then
     Exit Do
    End If
  • Type missmatch


    I get a type missmatch when I put in the IF statement.


    Do

    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=", "
    Selection.MoveRight Unit:=wdCharacter, Count:=8

    If wdCharacter = "" Then
    Exit Do


    End If
    Loop


    End Sub


    Any thoughts? Thanks for taking the time!

  • Re: Word Loop macro


    It's not defined. The is the code that was created by using the record macro feature. How should I define it, or can it define it?


    Thanks again!!

  • Re: Word Loop macro


    Now I am getting a Type Missmatch on the first line of the code. The macro essentially is suppose to put the cursor at the end of the first number, select Delete to bring the next number up to the same line. Then insert and comma and a space...then repeat.


    wdCharacter is what I am assuming is the cursor movements; would this be considered something other than a string?

  • Re: Word Loop macro


    Finally figured something out. I changed the MoveRight to 7 instead of 8 because in my attempted recreation of what I assumed you file looked like, it only works as a 7.



    Also, please use the code tags when posting code from now on.

  • Re: Word Loop macro


    Sorry, I am probably driving you crazy, but really appreciate your help. I ran the macro and did not get an error, however, it just did one number and stopped, as shown below: :?


    14764367, 1476437
    14764393
    14765663
    14765713
    14765739
    14765952
    14766000
    14766133
    14767842
    14767883
    14767909
    14767974
    14767982
    14768188
    14768204
    14768212
    14768279
    14770499
    14770507
    14770515
    14770523
    14770531
    14770580
    14770598
    14770606
    14770648
    14770721
    14760342
    14770002
    14770036
    14770085
    14770119
    14770127
    14770168
    14770184

  • Re: Word Loop macro


    Per your original post, all the strings were 7 in length.


    According to the sample you just posted, they're all 8.


    Change the count to the ACTUAL length of each string.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!