Remove 2 Characters from the end of each line?

J

Jgrant

Hi :)

I'm wondering if it's possible to record a macro, or code one, or i
there's some easy function that will remove two characters from the en
of each line in Word. The lines are all different lengths.

Also, is there anyway to make Word remove blank lines? (No character
or anything. Just like if you hit enter twice. There's that line wit
nothing in it?
 
D

DeanH

Firstly, try the quick and simple, select the text, click on the Centre align
icon (Ctrl+E), then the Left align icon (Ctrl+L), this usually gets rid of
any superfluous spaces and tabs from the start and end of paragraphs.
For multiple paragraphs you can use Find/Replace, using ^p^p for the find
and ^p for the replace, this will get rid of two paragraph marks and replace
with one.
See http://sbarnhill.mvps.org/WordFAQs/CleanWebText.htm for this and other
tips, also see http://gregmaxey.mvps.org/Clean_Up_Text.htm for a macro that
can help if you need to do this a lot.
 
J

Jgrant

Alright, and how do I make it remove the last 2 characters? They ar
usually a - and a space, but it is sometimes something else, so I nee
it to remove the last 2 characters.
 
G

Graham Mayor

'Line' is a vague concept in Word as lines are totally dependent on text
flow and content. Are these 'lines' in fact paragraphs - terminated with a
paragraph mark ¶? In which case the following macro will both remove any
empty paragraphs and remove the last two characters (excluding the paragraph
mark) of each line

Sub Remove2Chars()
Dim oRng As Range
Dim i As Long
With ActiveDocument
For i = .Paragraphs.Count To 1 Step -1
Set oRng = .Paragraphs(i).Range
With oRng
.End = .End - 1
If .Text = "" Then .Delete
.Characters.Last.Delete
.Characters.Last.Delete
End With
Next i
End With
End Sub

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jgrant

That didn't work at all.

I have this sort of a thing:
Victorian Hat Black - shop[4] - 650 -
Victorian Hat White - shop[4] - 650 -
Victorian Hat Green - shop[4] - 650 -
Victorian Hat Beige - shop[4] - 650 -

I want the last - removed, because it's pointless, but it is followed
by a space.
 
G

Graham Mayor

As I indicated in my previous post, 'line' is a vague concept. The macro I
quoted removes the last two characters from each *paragraph*. Click the ¶
button (or CTRL+*) to display the hidden characters then see what the
makeup of the line endings really is and what the line termination
characters are.

However if all the lines are similar in layout to the list you quoted, you
can tackle it a different way

Use Replace with the wildcard option set to replace
(\] - [0-9]{3}) -
with
\1

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

That didn't work at all.

I have this sort of a thing:
Victorian Hat Black - shop[4] - 650 -
Victorian Hat White - shop[4] - 650 -
Victorian Hat Green - shop[4] - 650 -
Victorian Hat Beige - shop[4] - 650 -

I want the last - removed, because it's pointless, but it is followed
by a space.
Graham said:
'Line' is a vague concept in Word as lines are totally dependent on
text

flow and content. Are these 'lines' in fact paragraphs - terminated
with a
paragraph mark ¶? In which case the following macro will both remove
any
empty paragraphs and remove the last two characters (excluding the
paragraph
mark) of each line

Sub Remove2Chars()
Dim oRng As Range
Dim i As Long
With ActiveDocument
For i = .Paragraphs.Count To 1 Step -1
Set oRng = .Paragraphs(i).Range
With oRng
.End = .End - 1
If .Text = "" Then .Delete
.Characters.Last.Delete
.Characters.Last.Delete
End With
Next i
End With
End Sub

http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - Word MVP





Jgrant wrote:-
Alright, and how do I make it remove the last 2 characters? They are
usually a - and a space, but it is sometimes something else, so I
need
it to remove the last 2 characters.
DeanH;432759 Wrote:-
Firstly, try the quick and simple, select the text, click on the
Centre align
icon (Ctrl+E), then the Left align icon (Ctrl+L), this usually gets
rid of
any superfluous spaces and tabs from the start and end of paragraphs.
For multiple paragraphs you can use Find/Replace, using ^p^p for the
find
and ^p for the replace, this will get rid of two paragraph marks and
replace
with one.
See http://sbarnhill.mvps.org/WordFAQs/CleanWebText.htm for this and
other
tips, also see http://gregmaxey.mvps.org/Clean_Up_Text.htm for a
macro that
can help if you need to do this a lot.
--
Hope this helps
DeanH


:
-

Hi :)

I'm wondering if it's possible to record a macro, or code one, or if
there's some easy function that will remove two characters from the
end
of each line in Word. The lines are all different lengths.

Also, is there anyway to make Word remove blank lines? (No characters
or anything. Just like if you hit enter twice. There's that line with
nothing in it?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top