Table 1st col Insert Word

J

Jen

I want to insert

Dr^s (non breaking space)

as 1st word in Column 1 of a table (the rows already exist). I just want it
to run down the 1st column and insert the above word with a nonbreaking
space before the text already inserted? Is anyone able to help with VBA
please?

Much appreciated.
 
H

Helmut Weber

Hi Jen,

like that:

Sub TestDr()
Dim oTbl As Table
Dim oRow As Row
Dim sTmp As String
Set oTbl = Selection.Tables(1)
For Each oRow In oTbl.Rows
With oRow.Range.Cells(1).Range
If Left(.Text, 3) <> "Dr" & Chr(160) Then
sTmp = Left(.Text, Len(.Text) - 2)
sTmp = "Dr" & Chr(160) & sTmp
.Text = sTmp
End If
End With
Next
End Sub

Post back, if you have vertically merged cells,
as in that case things get a bit more complicated.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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