Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Split table cells

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex St-Pierre - 23 Nov 2007 21:51 GMT
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
Signature

Alex St-Pierre

Doug Robbins - Word MVP - 24 Nov 2007 04:54 GMT
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

Signature

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

> Hi!
> In a word table, the cell(2,2) contains this informations:
[quoted text clipped - 11 lines]
> Thank you!
> Alex
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.