Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-23-2014, 10:16 AM
jpb103's Avatar
jpb103 jpb103 is offline Copying text range of cells to different cells adds an extra line Windows 7 64bit Copying text range of cells to different cells adds an extra line Office 2007
Advanced Beginner
Copying text range of cells to different cells adds an extra line
 
Join Date: May 2014
Location: Thunder Bay, Ontario
Posts: 58
jpb103 is on a distinguished road
Default Copying text range of cells to different cells adds an extra line

Hey Fellas,



I've got a macro that moves the text from one cell to another. The code goes something like this:
Code:
Dim oRow as Row
set oRow = ActiveDocument.Tables(2).Rows.Add
oRow.Cells(1).Range.Text = ActiveDocument.Tables(1).Rows(1).Range.Cells(1).Text
The problem I'm having is that when the text is copied over to the new cell, it adds an extra line on the end. Any thoughts, Word VBA community?
Reply With Quote
  #2  
Old 07-23-2014, 12:21 PM
gmaxey gmaxey is offline Copying text range of cells to different cells adds an extra line Windows 7 32bit Copying text range of cells to different cells adds an extra line Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRow As Row
  Set oRow = ActiveDocument.Tables(2).Rows.Add
  'You need to strip the end of cell marker.  This is a little cumbersome inline:
  oRow.Cells(1).Range.Text = Left(ActiveDocument.Tables(1).Rows(1).Range.Cells(1).Range.Text, _
                             Len(ActiveDocument.Tables(1).Rows(1).Range.Cells(1).Range.Text) - 2)
  'So use a function instead
  oRow.Cells(1).Range.Text = CellContent(ActiveDocument.Tables(1).Rows(1).Range.Cells(1))
End Sub
 Function CellContent(oCell As Cell) As String
Dim oRng As Word.Range
   Set oRng = oCell.Range
   oRng.End = oRng.End - 1
   CellContent = oRng.Text
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-23-2014, 12:22 PM
jpb103's Avatar
jpb103 jpb103 is offline Copying text range of cells to different cells adds an extra line Windows 7 64bit Copying text range of cells to different cells adds an extra line Office 2007
Advanced Beginner
Copying text range of cells to different cells adds an extra line
 
Join Date: May 2014
Location: Thunder Bay, Ontario
Posts: 58
jpb103 is on a distinguished road
Default

Thanks Greg, I'll try this out tomorrow.
Reply With Quote
Reply

Tags
cells, copying, tables

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Color-fill a range of cells, based on text in a different sheet. Possible? unittwentyfive Excel 2 06-01-2014 06:48 AM
Copying a formula that uses pivottable cells Paul46 Excel 0 02-08-2014 07:04 AM
Copying text range of cells to different cells adds an extra line Copying cells isminoh Excel 5 04-18-2012 11:49 AM
Copying text range of cells to different cells adds an extra line Set range for merged Word table cells? tinfanide Word VBA 1 02-06-2012 05:57 AM
Count range cells eliminating merge cells danbenedek Excel 0 06-15-2010 12:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:44 AM.


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