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

Split table cells

 
Post new topic   Reply to topic    Computer Forum Forum Index -> word vba customization
View previous topic :: View next topic  
Author Message
Alex St-Pierre
Guest





PostPosted: Fri Nov 23, 2007 9:51 pm    Post subject: Split table cells Reply with quote

Hi!
In a word table, the cell(2,2) contains this informations:
Male/Female (enter)
20/30 (enter)
30/40 (enter)
40/50 (enter)
etc.
I'm wondering if there's a way to detect that there's a "/" in the cell and
split the informations in two columns?
1) Look if there is a "/" and split the cells in two (vertical split)
2) Put all the informations at the left of the "/" in the left column and
right informations in the right column (for each line).
Thank you!
Alex
--
Alex St-Pierre
Back to top
Google
Sponsor





PostPosted: Fri Nov 23, 2007 9:51 pm    Post subject: Advertisement

Back to top
Doug Robbins - Word MVP
Guest





PostPosted: Sat Nov 24, 2007 4:54 am    Post subject: Re: Split table cells Reply with quote

This should do it:

Dim myrange As Range, myarray As Variant, str1 As String, str2 As String, i
As Long
With ActiveDocument.Tables(1).Cell(2, 2)
Set myrange = .Range
If InStr(myrange, "/") > 0 Then
myrange.Text = Replace(myrange.Text, Chr(13), "/")
myarray = Split(myrange.Text, "/")
.Split 1, 2
End If
End With
str1 = ""
For i = 0 To UBound(myarray) - 2 Step 2
str1 = str1 & myarray(i) & vbCr
Next i
str1 = Left(str1, Len(str1) - 1)
str2 = ""
For i = 1 To UBound(myarray) - 1 Step 2
str2 = str2 & myarray(i) & vbCr
Next i
str2 = str2 & myarray(UBound(myarray))
str2 = Replace(str2, Chr(13) & Chr(13), "")
ActiveDocument.Tables(1).Cell(2, 2).Range.Text = str1
ActiveDocument.Tables(1).Cell(2, 3).Range.Text = str2


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Alex St-Pierre" <AlexStPierre@discussions.microsoft.com> wrote in message
news:E202666B-4459-41AE-B1E0-29F5C252D66A@microsoft.com...
Quote:
Hi!
In a word table, the cell(2,2) contains this informations:
Male/Female (enter)
20/30 (enter)
30/40 (enter)
40/50 (enter)
etc.
I'm wondering if there's a way to detect that there's a "/" in the cell
and
split the informations in two columns?
1) Look if there is a "/" and split the cells in two (vertical split)
2) Put all the informations at the left of the "/" in the left column and
right informations in the right column (for each line).
Thank you!
Alex
--
Alex St-Pierre
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> word vba customization 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