Log in

View Full Version : [SOLVED:] Replace function adds carriage return



AJS
09-23-2019, 09:34 PM
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

macropod
09-24-2019, 12:41 AM
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.

AJS
09-24-2019, 02:57 PM
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.