Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

merging cells using VB

 
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba general
View previous topic :: View next topic  
Author Message
Carrie_Loos via OfficeKB.
Guest





PostPosted: Fri Dec 21, 2007 6:24 pm    Post subject: merging cells using VB Reply with quote

I have a row of 1's and 0's. I would like to merge all the cells with 1's
that are grouped in a row and not merge the 0's.
Example:

1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1
1

So that the cells with 1's in them merge and the cells with 0's in them do
not merge.

Is is possible?

Thanks in advance
Carrie

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200712/1
Back to top
Google
Sponsor





PostPosted: Fri Dec 21, 2007 6:24 pm    Post subject: Advertisement

Back to top
Helmut Weber
Guest





PostPosted: Fri Dec 21, 2007 10:21 pm    Post subject: Re: merging cells using VB Reply with quote

Hi Carrie,

beware of line breaks by the news reader.

Sub Test0101x()
Dim oTbl As Table
Dim oRow As Row
Dim ocll As Cell
Set oTbl = ActiveDocument.Tables(1)
For Each oRow In oTbl.Rows
For Each ocll In oRow.Cells
' ocll.Select ' for testing
While Left(ocll, 1) = "1" And _
Left(ocll.Next, 1) = "1" And _
ocll.RowIndex = ocll.Next.RowIndex
ocll.Merge mergeto:=ocll.Next
ocll.Range.Text = Replace(ocll.Range.Text, Chr(13), "")
If ocll.Range =
oTbl.Range.Cells(oTbl.Range.Cells.Count).Range Then Exit Sub
Wend
Next
Next
End Sub


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Back to top
Carrie_Loos via OfficeKB.
Guest





PostPosted: Fri Dec 21, 2007 11:11 pm    Post subject: Re: merging cells using VB Reply with quote

Thank you, I can't wait to try this out!

Helmut Weber wrote:
Quote:
Hi Carrie,

beware of line breaks by the news reader.

Sub Test0101x()
Dim oTbl As Table
Dim oRow As Row
Dim ocll As Cell
Set oTbl = ActiveDocument.Tables(1)
For Each oRow In oTbl.Rows
For Each ocll In oRow.Cells
' ocll.Select ' for testing
While Left(ocll, 1) = "1" And _
Left(ocll.Next, 1) = "1" And _
ocll.RowIndex = ocll.Next.RowIndex
ocll.Merge mergeto:=ocll.Next
ocll.Range.Text = Replace(ocll.Range.Text, Chr(13), "")
If ocll.Range =
oTbl.Range.Cells(oTbl.Range.Cells.Count).Range Then Exit Sub
Wend
Next
Next
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200712/1
Back to top
Helmut Weber
Guest





PostPosted: Sat Dec 22, 2007 1:16 pm    Post subject: Re: merging cells using VB Reply with quote

Hi Carrie,

after one night's sleep there is a solution
without error trapping:

Sub Test0101xx()
Dim oTbl As Table
Dim oRow As Row
Dim ocll As Cell

Set oTbl = ActiveDocument.Tables(1)
For Each oRow In oTbl.Rows
For Each ocll In oRow.Cells
While Left(ocll, 1) = "1" And _
Left(ocll.Next, 1) = "1" And _
ocll.RowIndex = ocll.Next.RowIndex
ocll.Merge mergeto:=ocll.Next
ocll.Range.Text = Replace(ocll.Range.Text, Chr(13), "")
If ocll.Next Is Nothing Then Exit Sub
Wend
Next
Next
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba general All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum