Copy line data from xml file path based on column data in active sheet

TD9010

New Member
Joined
Nov 22, 2017
Messages
2
Good Morning,

im trying to copy data from an xml file to an active sheet... i will try to explain it logically.

Table of Data

A b c
Xml File location String to Search Resulting Data
C:\temp\Test01.xmlSt001
C:\temp\Test01.xmlSt002
C:\temp\Test02.xmlSt001

<tbody>
</tbody>

I want to search each file that is defined in column A for the String that is defined in column B and then when it finds the string paste the line of data from the .xml into column C.

Example -

1. Search (A1)C:\temp\Test01.xml for (A)St001
2. Identify what line number St001 is on
3. Copy that line of data to cell C1

then move on to the next row until there is a blank cell and stop..

Can any one Help?

Cheers Tom.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Good evening Tom

Code:
Sub XML_files()
Dim i%, nw As Workbook, r As Range, sh As Worksheet, v%
Set sh = ActiveWorkbook.Sheets("cases")                 ' where destination table is
For i = 2 To sh.Range("b" & Rows.Count).End(xlUp).Row
    Set nw = Workbooks.OpenXML(sh.Cells(i, 1), , xlXmlLoadImportToList) ' open as table
    Set r = nw.ActiveSheet.Cells.Find(sh.Cells(i, 2), LookIn:=xlValues) ' find string
    v = nw.ActiveSheet.ListObjects(1).DataBodyRange.Columns.Count
    Set r = nw.ActiveSheet.Range(Cells(r.Row, 1), Cells(r.Row, v))
    r.Copy sh.Cells(i, 3).Resize(1, v)                                  ' copy row
    nw.Close 0
Next
End Sub
 
Upvote 0
Good evening Tom

Code:
Sub XML_files()
Dim i%, nw As Workbook, r As Range, sh As Worksheet, v%
Set sh = ActiveWorkbook.Sheets("cases")                 ' where destination table is
For i = 2 To sh.Range("b" & Rows.Count).End(xlUp).Row
    Set nw = Workbooks.OpenXML(sh.Cells(i, 1), , xlXmlLoadImportToList) ' open as table
    Set r = nw.ActiveSheet.Cells.Find(sh.Cells(i, 2), LookIn:=xlValues) ' find string
    v = nw.ActiveSheet.ListObjects(1).DataBodyRange.Columns.Count
    Set r = nw.ActiveSheet.Range(Cells(r.Row, 1), Cells(r.Row, v))
    r.Copy sh.Cells(i, 3).Resize(1, v)                                  ' copy row
    nw.Close 0
Next
End Sub

worked great thank you.
 
Upvote 0

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top