Insert Paragraph Mark in all Table Cells

A

Al

I need to have a macro that can insert a Paragraph Mark at the end of every
cell in a table.

I am trying to code this myself from examples but am having no luck

This code offers some hope - I found it from the WordTips site - cycles
through all selected cells but replaces the contents of every cell with
what's in the clipboard, I want to append a Paragraph Mark at the end of the
cell contents.

Sub PasteToCells()
Dim TargetRange As Range
Dim oTargCell As Cell

If Selection.Cells.Count = 0 Then
'Quit if no cells in selection
MsgBox "No cells selected", vbCritical
Exit Sub
End If
On Error Resume Next
Set TargetRange = Selection.Range
For Each oTargCell In Selection.Cells
oTargCell.Range.Paste
Next oTargCell
TargetRange.Select
End Sub

Thank-you
Al
 
M

macropod

Hi Al,

Try:
Sub InsertCellParas()
Dim TargetRange As Range
Dim oTargCell As Cell

If Selection.Cells.Count = 0 Then
'Quit if no cells in selection
MsgBox "No cells selected", vbCritical
Exit Sub
End If
On Error Resume Next
Set TargetRange = Selection.Range
For Each oTargCell In Selection.Cells
oTargCell.Range.Text = oTargCell.Range.Text
Next oTargCell
TargetRange.Select
End Sub

or, slightly re-worked:

Sub InsertCellParas()
Dim TargetRange As Range
Dim oTargCell As Cell
With Selection
If .Cells.Count = 0 Then
'Quit if no cells in selection
MsgBox "No cells selected", vbCritical
Exit Sub
End If
On Error Resume Next
Set TargetRange = .Range
For Each oTargCell In .Cells
oTargCell.Range.Text = oTargCell.Range.Text
Next
End With
TargetRange.Select
End Sub

Although the code might not seem to be doing anything, "oTargCell.Range.Text = oTargCell.Range.Text" actually causes a para mark to
be inserted.

Cheers
 
A

Al

Thank-you - that is perfect
Much appreciated
Al


macropod said:
Hi Al,

Try:
Sub InsertCellParas()
Dim TargetRange As Range
Dim oTargCell As Cell

If Selection.Cells.Count = 0 Then
'Quit if no cells in selection
MsgBox "No cells selected", vbCritical
Exit Sub
End If
On Error Resume Next
Set TargetRange = Selection.Range
For Each oTargCell In Selection.Cells
oTargCell.Range.Text = oTargCell.Range.Text
Next oTargCell
TargetRange.Select
End Sub

or, slightly re-worked:

Sub InsertCellParas()
Dim TargetRange As Range
Dim oTargCell As Cell
With Selection
If .Cells.Count = 0 Then
'Quit if no cells in selection
MsgBox "No cells selected", vbCritical
Exit Sub
End If
On Error Resume Next
Set TargetRange = .Range
For Each oTargCell In .Cells
oTargCell.Range.Text = oTargCell.Range.Text
Next
End With
TargetRange.Select
End Sub

Although the code might not seem to be doing anything, "oTargCell.Range.Text = oTargCell.Range.Text" actually causes a para mark to
be inserted.

Cheers

--
macropod
[MVP - Microsoft Word]
-------------------------

Al said:
I need to have a macro that can insert a Paragraph Mark at the end of every
cell in a table.

I am trying to code this myself from examples but am having no luck

This code offers some hope - I found it from the WordTips site - cycles
through all selected cells but replaces the contents of every cell with
what's in the clipboard, I want to append a Paragraph Mark at the end of the
cell contents.

Sub PasteToCells()
Dim TargetRange As Range
Dim oTargCell As Cell

If Selection.Cells.Count = 0 Then
'Quit if no cells in selection
MsgBox "No cells selected", vbCritical
Exit Sub
End If
On Error Resume Next
Set TargetRange = Selection.Range
For Each oTargCell In Selection.Cells
oTargCell.Range.Paste
Next oTargCell
TargetRange.Select
End Sub

Thank-you
Al
 
C

challa prabhu

Do the following:
1. Open the word document
2. Create a table with three cloumns - Just for an example.
3. Type just one character in each cell - Alternatevely copy the single
character and paste in other cells.
4. Select the whole table - click the table sysmbol on the left top corner
of the table.
5. On the Edit menu, click Replace.
6. Click the More button.
7. Click the curson in the Find what box, and then click the Special button.
8. Click Any character - ^? characters are entered in the box.
9. Click the curson in the Replace With box, and then click the Special
button.
8. Click Paragraph character- ^v characters are entered in the box.
9. Click Replace button.
Important: Do not click Replace all. Because you are highlighing the table,
the command has to be executed within the table only. You click Replace ALL
then all contents in the document will be replaced by the paragaraph mark.

Challa Prabhu
 

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