How do I replace non-constants in word?

  • Thread starter Thread starter Terry D
  • Start date Start date
T

Terry D

Is there any way that I can replace in word when something is not constant? I
am copying columns over from Excel. Some are in two columns and some are in
three. A, B and C change on each line

For example I need to replace
A tab tab B tab tab C
with
A tab B tab C

I can't just replace tab tab with tab as this affects the two column and I
end up with A tab C. Do I use a wildcard and if so how do I do it?

Many thanks for any help you can give
 
Terry D said:
Is there any way that I can replace in word when something is not constant? I
am copying columns over from Excel. Some are in two columns and some are in
three. A, B and C change on each line

For example I need to replace
A tab tab B tab tab C
with
A tab B tab C

I can't just replace tab tab with tab as this affects the two column and I
end up with A tab C. Do I use a wildcard and if so how do I do it?

I am sorry, but I don't follow.

If, as you write, you have

A tab tab B tab tab C

and you do a Find/Replace where you replace "tab tab" by "tab," you will
end up with

A tab B tab C

not

A tab C
 
Jean-Guy Marcil said:
I am sorry, but I don't follow.

If, as you write, you have

A tab tab B tab tab C

and you do a Find/Replace where you replace "tab tab" by "tab," you will
end up with

A tab B tab C

not

A tab C

Sorry it's a bit confusing:

What I'm trying to do is replace the following:

John [tab][tab]Michael [tab][tab]Jones
John[tab][tab]Smith
so can copy back into excel (where the [tab] is a column break
I need the [tab][tab]Michael[tab][tab] to be [tab]Michael][tab] where
Michael is a variable.

if I replace [tab][tab] with [tab] it changes the John Smith line and that
needs to stay the same.

Hope this makes more sense.
 
Am I correct that two consecutive tabs corresponds to an empty cell between
those two tabs? And, a line that begins with a tab indicates that the 1st
cell in that row is empty?

If so, I'd do this in multiple steps, and replace all of the empty cells
with token placeholders you can delete later on.

1. Find:^p^t
Replace:^p[placeholder]^t

This puts a placeholder at the begging of any row with an empty first cell.

2. Find:^t^t
Replace:^t[placeholder]^t

This puts placeholders in the interior for any empty cell.

3. Find:^t^p
Replace:^t[placeholder]^p

This puts a placeholder at the end of any row with an empty last cell.

But.. a bigger question is "Why do you have tabs at all?" When pasting
to/from Excel, it's possible to paste as a Word table, then paste back into
Excel's row/column structure, which are far easier to work with than tabbed
columns.
 
Terry D said:
Sorry it's a bit confusing:

What I'm trying to do is replace the following:

John [tab][tab]Michael [tab][tab]Jones
John[tab][tab]Smith
so can copy back into excel (where the [tab] is a column break
I need the [tab][tab]Michael[tab][tab] to be [tab]Michael][tab] where
Michael is a variable.

if I replace [tab][tab] with [tab] it changes the John Smith line and that
needs to stay the same.

Try this:

Find What:
([A-z0-9 ]@^t)^t([A-z0-9 ]@^t)^t([A-z0-9 ]@^13)
Replace with:
\1\2\3

Make sure to turn on the Wild card option (Click on More first).

The above means:
([A-z0-9 ]@^t) = [any letter, any number or space]any number of occurences
of the preceding(@) followed by a tab(^t). The ( ) indicate that this is
group.

^t = a tab (Not part of any groups, it is not in between any pair of
brackets.)

([A-z0-9 ]@^t)^t = [any letter, any number or space]any number of occurences
of the preceding followed by a tab. The ( ) indicate that this is group.

^t = a tab

([A-z0-9 ]@^13)= [any letter, any number or space]any number of occurences
of the preceding followed by a paragraph mark(¶). The ( ) indicate that this
is group.

Replace with
\1 = The first group
\2 = The second group
\3 = The third group

So, this deletes the extra tabs.
 
Replace
^t(^t<[A-Za-z]{1,}>^t)^t
with
\1
with the wildcard option set
http://www.gmayor.com/replace_using_wildcards.htm

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

My web site www.gmayor.com

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


Terry said:
Jean-Guy Marcil said:
I am sorry, but I don't follow.

If, as you write, you have

A tab tab B tab tab C

and you do a Find/Replace where you replace "tab tab" by "tab," you
will end up with

A tab B tab C

not

A tab C

Sorry it's a bit confusing:

What I'm trying to do is replace the following:

John [tab][tab]Michael [tab][tab]Jones
John[tab][tab]Smith
so can copy back into excel (where the [tab] is a column break
I need the [tab][tab]Michael[tab][tab] to be [tab]Michael][tab] where
Michael is a variable.

if I replace [tab][tab] with [tab] it changes the John Smith line and
that needs to stay the same.

Hope this makes more sense.
 
Graham Mayor said:
Replace
^t(^t<[A-Za-z]{1,}>^t)^t

or

^t(^t<[A-z0-9 ]@>^t)^t

in case there are numbers or spaces...


Much more elegant to look only for the middle column instead of the whole
line as I did!
 
Back
Top