Doug Robbins - Word MVP Guest
|
Posted: Sat Nov 24, 2007 4:54 am Post subject: Re: Split table cells |
|
|
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 |
|
|