Hi Guys!
I have the following code that gets data from tables within a word document then copies this data to an excel spreadsheet.
How do I get the code to put each specific value to a specic excel cell as it goes through the loop. Eg when executing first loop I want the result to appear in cell D3, the next loop S6 etc. At the moment the code is only putting all values in one excel column (D column)(as specified in:ws.Cells(y - 2, 4).Value = t.Cell(y, 5).Range.Text
Many thanks,
I have the following code that gets data from tables within a word document then copies this data to an excel spreadsheet.
How do I get the code to put each specific value to a specic excel cell as it goes through the loop. Eg when executing first loop I want the result to appear in cell D3, the next loop S6 etc. At the moment the code is only putting all values in one excel column (D column)(as specified in:ws.Cells(y - 2, 4).Value = t.Cell(y, 5).Range.Text
Code:
Sub WordToExcel()
Dim MyWd As Object
'Dim myExc As Excel.Sheets
Dim ws As Worksheet
Set MyWd = GetObject("folder path")
Set ws = ActiveWorkbook.Sheets("Sheet1")
x = 0
For Each t In MyWd.Tables
x = x + 1
Debug.Print "Table: ", x
Debug.Print "Rows: ", t.Rows.Count
Debug.Print "Value in first cell: ", t.Cell(1, 1).Range.Text
If InStr(1, t.Cell(1, 1).Range.Text, "industry", vbTextCompare) > 0 Then
y = 3
Do While InStr(1, t.Cell(y, 2).Range.Text, "total", vbTextCompare) = 0
Debug.Print , t.Cell(y, 5).Range.Text
'ws.Cells(y - 2, 1).Value = t.Cell(y, 2).Range.Text
ws.Cells(y - 2, 4).Value = t.Cell(y, 5).Range.Text
y = y + 1
Loop
End If
Next
End Sub
Many thanks,
Last edited: