Log in

View Full Version : Remove nth character from END (right) of cell in Word Table



Lurker
08-29-2012, 08:58 AM
Hi there,

As a VBA novice I would be very grateful for help on this issue, I have searched this site and others to no avail.

(In a macro running on a Word doc table) the line below removes the final 3 characters of my cell text. However, I need only the THIRD-TO-LAST character removing, and the final two left intact. (i.e. the nth character from the right-hand end of the cell). [I have already taken end-of-cell markers into account by the way, that isn't the issue... for now anyway!]

oCell.Range.Text= Mid(oCell.Range.Text, 1, Len(oCell.Range.Text) - 3)

All other questions on the web cover nth character from start of cell/string; I can't find nth character counting back from the right.

Very many thanks (and quite a lot of awe) in advance.

fumei
08-29-2012, 12:05 PM
Concatenate TWO Mid functions?

One getting a string from the start to n-1, plus the other from n+1 to the end. Thus n is removed.

Frosty
08-29-2012, 01:03 PM
I'd skip the mid... and simply do...

With oCell.Range
.Text = Left(.Text, Len(.Text) - 5) & Right(.Text, 4)
End With

If you weren't dealing with the end of cell characters, the values would be 2 less ( - 3 and 2), but I think that would work for you.