Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-17-2012, 12:53 PM
KD999 KD999 is offline Macro to Merge Cells Row By Row in a Table Windows XP Macro to Merge Cells Row By Row in a Table Office 2007
Novice
Macro to Merge Cells Row By Row in a Table
 
Join Date: Feb 2012
Posts: 4
KD999 is on a distinguished road
Default Macro to Merge Cells Row By Row in a Table

Hi,

I need help creating a macro which will merge particular cells within a table for multiple rows but leave the rows separate.

In my table I've got 8 columns and 20 rows. In each of the 20 rows I want to merge the data in columns 2, 3 & 4.

I've picked up the following macro which will merge the Cells but I need it to loop through the rest of the table.

Sub MergeCellsRowByRow()


'
' MergeCellsRowByRow Macro
'
'
Dim myCells As Range
Dim r As Row
With ActiveDocument
Set myCells = .Range(Start:=.Tables(1).Cell(1, 2).Range.Start, End:=.Tables(1).Cell(1, 4).Range.End)
myCells.Select
End With

Selection.Cells.Merge

End Sub

Thanks in advance
Reply With Quote
  #2  
Old 02-17-2012, 07:15 PM
macropod's Avatar
macropod macropod is offline Macro to Merge Cells Row By Row in a Table Windows 7 64bit Macro to Merge Cells Row By Row in a Table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi KD999,

Try:
Code:
Sub MergeData()
Dim Rng As Range, TblRw As Row
With ActiveDocument.Tables(1)
  For Each TblRw In .Rows
    Set Rng = TblRw.Cells(2).Range
    Rng.End = TblRw.Cells(4).Range.End
    Rng.Cells.Merge
  Next
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-18-2012, 01:44 AM
KD999 KD999 is offline Macro to Merge Cells Row By Row in a Table Windows XP Macro to Merge Cells Row By Row in a Table Office 2007
Novice
Macro to Merge Cells Row By Row in a Table
 
Join Date: Feb 2012
Posts: 4
KD999 is on a distinguished road
Smile Thank You

Thank you. I've just tried the macro you've supplied and it works brilliantly. First time posting on one of these forums and my query was resolved first go
Reply With Quote
  #4  
Old 02-20-2012, 03:32 AM
KD999 KD999 is offline Macro to Merge Cells Row By Row in a Table Windows XP Macro to Merge Cells Row By Row in a Table Office 2007
Novice
Macro to Merge Cells Row By Row in a Table
 
Join Date: Feb 2012
Posts: 4
KD999 is on a distinguished road
Default Loop Through Tables in Word and then perform a Merge

Hi (Reopened)

This is a follow on from my previous thread. I need to create a macro which will loop through tables in word (or be able to specify which table I want to update) and then perform the row by row column merge as provided to me over the weekend.

Sub MergeTableRowByRow()

Dim Rng As Range, TblRw As Row
With ActiveDocument.Tables(1)
For Each TblRw In .Rows
Set Rng = TblRw.Cells(2).Range
Rng.End = TblRw.Cells(3).Range.End
Rng.Cells.Merge
Next
End With
End Sub

My word document has a number of tables which each have a different numbers of columns/rows and it's only one particular table in my document that I need to run the above merge for.

Update:
I can hardcode the table in the ActiveDocument.Tables(x) but some users have not created the document in the same format so one users Table 9 could be another users Table 12. I will therefore need to be perform a loop through the tables until I see the one what I need on the screen and once located perform the above merge.

Thanks in advance.

Last edited by KD999; 02-20-2012 at 04:52 AM. Reason: Doesn't work
Reply With Quote
  #5  
Old 02-20-2012, 08:51 PM
macropod's Avatar
macropod macropod is offline Macro to Merge Cells Row By Row in a Table Windows 7 64bit Macro to Merge Cells Row By Row in a Table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi KD999,

What you need, then, is a means of identifying the table in question. For example, is there always a particular cell that contains something that is unique to the table you're interested in?

As it's really the same topic as before, I've merged the threads.

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to Merge Cells Row By Row in a Table VBA and hyperlinks in table cells viuf PowerPoint 13 02-19-2012 10:34 AM
Macro to Merge Cells Row By Row in a Table Word VBA: add textboxs in table cells? tinfanide Word VBA 12 02-09-2012 12:05 AM
Macro to Merge Cells Row By Row in a Table put a border around table cells that have text in them tonywatsonmail Mail Merge 1 01-31-2012 04:37 AM
Macro to Merge Cells Row By Row in a Table Unwanted tabs in table cells deltaskye Word 5 01-27-2012 11:58 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 06:43 PM.


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