moving table data from cell to cell

T

Tony Logan

I need a macro that examines a table within a document,
checks for table cells containing only a dollar sign and
nothing else, then moves the dollar sign one cell to the
right. This should happen for every dollar-sign-only cell
in the table.

I suspect some sort of loop is needed, but so far I can
only make this work for the first occurence.

I'd be thankful for any help.

-Tony
 
D

Doug Robbins - Word MVP

Hi Tony,

The following code will move the $ sign to the next non-empty cell to the
right. If none of the cells to the right contain data, the $ sign will
endup in the last column.

Dim i As Integer, j As Integer, test As Range
For i = 1 To ActiveDocument.Tables(1).Rows.Count
For j = 1 To ActiveDocument.Tables(1).Rows(i).Cells.Count - 1
Set test = ActiveDocument.Tables(1).Cell(i, j).Range
test.End = test.End - 1
If test = "$" Then
test.Delete
ActiveDocument.Tables(1).Cell(i, j + 1).Range.InsertBefore "$"
End If
Next j
Next i

If you just want it to move the $ sign one cell to the right regardless of
whether that cell contains any data, use

Dim i As Integer, j As Integer, test As Range
For i = 1 To ActiveDocument.Tables(1).Rows.Count
For j = 1 To ActiveDocument.Tables(1).Rows(i).Cells.Count - 1
Set test = ActiveDocument.Tables(1).Cell(i, j).Range
test.End = test.End - 1
If test = "$" Then
test.Delete
ActiveDocument.Tables(1).Cell(i, j + 1).Range.InsertBefore "$"
Exit For
End If
Next j
Next i


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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