Hi =?Utf-8?B?UmFt?=,
> I am creating multiple page word document. Here is what I would like to do
> on each page.
[quoted text clipped - 5 lines]
> copy particular cell and then paste it in the second cell of first column,
> second page.
Here's some sample code
Sub CopyTableCell()
Dim rngPg1 As Word.Range
Dim rngPg2 As Word.Range
Dim rngCell1 As Word.Range
Dim rngCell2 As Word.Range
'Move to the top of the document
Selection.HomeKey wdStory
'Pick up the entire page of the active selection
Set rngPg1 = ActiveDocument.Bookmarks("\Page").Range
'Pick up the last row, first cell
Set rngCell1 = rngPg1.Rows(rngPg1.Rows.Count).Cells(1).Range
'Shorten the range to drop the end-of-cell marker
rngCell1.MoveEnd wdCharacter, -1
'Move to the second page
Selection.GoTo What:=wdGoToPage, Which:=2
'Pick up the entire page
Set rngPg2 = ActiveDocument.Bookmarks("\Page").Range
'Pick up the first cell of the second row
Set rngCell2 = rngPg2.Rows(2).Cells(1).Range
'Make sure the range is IN the cell (not containing the cell)
rngCell2.Collapse
'"Copy" the text + formatting
rngCell2.FormattedText = rngCell1.FormattedText
Debug.Print rngPg2.Rows.Count, rngCell1.Text
End Sub
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Ram - 13 Jan 2006 00:13 GMT
Hi,
Thanks for the code. I will try. Thanks a lot.
> Hi =?Utf-8?B?UmFt?=,
>
[quoted text clipped - 44 lines]
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)
Ram - 13 Jan 2006 14:21 GMT
Hi,
I tried. Its working. I am more of learning VBA. Instead of copying last
cell content of first column on first page and copying into second cell of
first column on second page, Is it possible to copy last non empty cell
content of first column and paste it into the second page second cell of
first column. If it is possible that would be great. And I want to do this
repetetively for every page of the table. Here is the code that I you
provided me last time. Thank you.
Sub CopyTableCell()
Dim rngPg1 As Word.Range
Dim rngPg2 As Word.Range
Dim rngCell1 As Word.Range
Dim rngCell2 As Word.Range
'Move to the top of the document
Selection.HomeKey wdStory
'Pick up the entire page of the active selection
Set rngPg1 = ActiveDocument.Bookmarks("\Page").Range
'Pick up the last row, first cell
Set rngCell1 = rngPg1.Rows(rngPg1.Rows.Count).Cells(1).Range
'Shorten the range to drop the end-of-cell marker
rngCell1.MoveEnd wdCharacter, -1
'Move to the second page
Selection.GoTo What:=wdGoToPage, Which:=2
'Pick up the entire page
Set rngPg2 = ActiveDocument.Bookmarks("\Page").Range
'Pick up the first cell of the second row
Set rngCell2 = rngPg2.Rows(2).Cells(1).Range
'Make sure the range is IN the cell (not containing the cell)
rngCell2.Collapse
'"Copy" the text + formatting
rngCell2.FormattedText = rngCell1.FormattedText
Debug.Print rngPg2.Rows.Count, rngCell1.Text
End Sub
> Hi =?Utf-8?B?UmFt?=,
>
[quoted text clipped - 44 lines]
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)
Ram - 14 Jan 2006 19:08 GMT
Hi,
I tried. Its working. I am more of learning VBA. Instead of copying last
cell content of first column on first page and copying into second cell of
first column on second page,I extended it to copy last non empty cell
content of first column and paste it into the second page second cell of
first column. Here is the code that I modified. And I want to do this
repetetively for every page of the table. Could you please tell me how to do
this on every page. Thank you.
Sub CopyTableCell()
Dim rngPg1 As Word.Range
Dim rngPg2 As Word.Range
Dim rngCell1 As Word.Range
Dim rngCell2 As Word.Range
'Move to the top of the document
Selection.HomeKey wdStory
'Pick up the entire page of the active selection
Set rngPg1 = ActiveDocument.Bookmarks("\Page").Range
'Pick up the last row, first cell
cellNumber = rngPg1.Rows.Count
Set rngCell1 = rngPg1.Rows(cellNumber).Cells(1).Range
'Shorten the range to drop the end-of-cell marker
rngCell1.MoveEnd wdCharacter, -1
Do Until cellNumber = 1
If rngCell1.Text = "" Then
cellNumber = cellNumber - 1
Set rngCell1 = rngPg1.Rows(cellNumber).Cells(1).Range
rngCell1.MoveEnd wdCharacter, -1
End If
If rngCell1.Text <> "" Then Exit Do
Loop
'Move to the second page
Selection.GoTo What:=wdGoToPage, Which:=2
'Pick up the entire page
Set rngPg2 = ActiveDocument.Bookmarks("\Page").Range
'Pick up the first cell of the second row
Set rngCell2 = rngPg2.Rows(1).Cells(1).Range
'Make sure the range is IN the cell (not containing the cell)
rngCell2.Collapse
'"Copy" the text + formatting
rngCell2.FormattedText = rngCell1.FormattedText
rngCell2.Paragraphs.Alignment = wdAlignParagraphLeft
Debug.Print rngPg2.Rows.Count, rngCell1.Text
End Sub
> Hi =?Utf-8?B?UmFt?=,
>
[quoted text clipped - 44 lines]
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)