Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-09-2019, 03:43 PM
Guessed's Avatar
Guessed Guessed is offline Copying text from last row of multiple tables of different lengths Windows 10 Copying text from last row of multiple tables of different lengths Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this version
Code:
Sub Results2()
  Dim i As Integer, iTables As Integer
  Dim aTbl As Table, tblLast As Table
  Dim aRng As Range, aRngEnd As Range
  
  iTables = ActiveDocument.Tables.Count
  Set tblLast = ActiveDocument.Tables(iTables)
  
  For i = 1 To iTables - 1
    Set aTbl = ActiveDocument.Tables(i)
    Set aRng = aTbl.Range.Cells(1).Range
    If InStr(aRng.Text, "Worksheet") > 0 Then
      Set aRngEnd = tblLast.Range
      aRngEnd.Collapse Direction:=wdCollapseEnd
      aRngEnd.FormattedText = aTbl.Rows.Last.Range.FormattedText
    End If
  Next i
End Sub
Note that you will likely encounter problems if your tables have merged cells or the cell counts are not consistent in the last rows.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compile text from multiple tables into a cell in a nested table jrooney7 Word VBA 2 03-11-2019 07:55 AM
Copying text from last row of multiple tables of different lengths Copying text into multiple cells at once BIMwit Word Tables 1 05-14-2015 09:50 PM
Ink to Text lines are different lengths raineysky OneNote 0 02-12-2015 11:21 AM
Copying text from last row of multiple tables of different lengths Copying multiple files as text without extensions Metamag Office 3 05-09-2011 06:25 PM
Copying text from last row of multiple tables of different lengths Copying Multiple tables from excel into a single word document dineshtgs Word Tables 1 04-07-2011 01:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft