How to extract value of cells from table to line?

A

avkokin

Hello.
I have a problem with a table again.
There is a table which has 8 columns (the number of rows maybe is
different).
the table contains next values (for example):
the cell of first column has type of date - 21/07/2008
the cell of second column has type of date - 30/07/2008
the cell of third column has type of data - 15
the cell of fourth column has type of data - 16
the cell of fifth column has type of data - 12000
the cells of sixth and seventh columns has type of data - ÈÈÈÈ.ÈÈ
the cell of eighth column hasn't data
I need extract of data from all columns of the table to the line to
the following type:
"from 21.07.2008 to 30.07.2008 - 12000 x 16% x 15 days x ÈÈÈÈ.ÈÈ"
I started to write the code (below) but I was lose one's train of
thought.
Help me. Maybe I should use a data array?

Sub colToLine()
Dim oTable As Table
Dim nRow As Long
Dim nCol As Long
Dim sStr As String
Dim sStr1 As String
Dim sStr2 As String
Dim oRange As Range

sStr1 = "from "
sStr2 = " to "
Set oTable = ActiveDocument.Tables(1)
Set oRange = Selection.Range

oRange.EndOf wdStory, wdMove
oRange.Collapse wdCollapseEnd
oRange.Select

For nRow = 1 To oTable.Rows.Count
For nCol = 1 To oTable.Columns.Count
sStr = oTable.Cell(nRow, nCol).Range.Text
sStr = Left(sStr, Len(sStr) - 2)

' oRange.InsertAfter sStr1 & sStr2 & " - " & ?????

Next nRow
End With

oTable.Delete

End Sub

Thank you very much.
 
G

Graham Mayor

Something like:

Dim oTable As Table
Dim oRow As Range
Dim vText As Variant
Dim sText As String
Dim i As Long
Dim dSource As Document
Dim dTarget As Document
Set dSource = ActiveDocument
Set dTarget = Documents.Add
Set oTable = dSource.Tables(1)
For i = 1 To oTable.Rows.Count
Set oRow = oTable.Rows(i).Range
vText = Split(oRow, Chr(13), -1)
sText = "from " & vText(0) & _
" to " & vText(1) & " - " _
& vText(4) & " x " & vText(3) _
& "% x " & vText(2) & _
" days x " & vText(5) & vbCr
sText = Replace(sText, Chr(7), "")
dTarget.Activate
Selection.TypeText sText
Next i


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top