Consulting

Results 1 to 3 of 3

Thread: Replace function adds carriage return

  1. #1
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location

    Replace function adds carriage return

    I'm trying to set up a macro to replace numbers in a selection with their subscript equivalent. However, when I execute the macro it adds a carriage return at the end of the selection. Any idea why / what I'm doing wrong?

    A barebones example of the code is below:

    Sub SubScriptNumbers()
    
        Dim rng As Range
        
        Set rng = Selection.Range
    
            rng = Replace(rng, "2", ChrW(8322))
            
    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,890
    Location
    I don't get any extraneous characters with your code. Why not simply subscript the numbers? After all, the characters you're inserting aren't subscripts - they're simply small characters.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Thanks for the reply, Paul.

    I rechecked the macro, and the additional carriage return only seems to appear when one is included in the selection - I hadn't noticed that before.
    I'm using subscript characters as I've found subscript formatting to be too easily lost - particularly when cutting and pasting between applications.

Posting Permissions

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