I have a number of identical XML reports stored in excel. In these reports, each item in one of the tables in each report a unique ID relating that item to a specific entity. Each entity has multiple items associated with it. Essentially, the structure of the macro I am looking for is as follows:
1) Excel searches for the ENTITY title tag in the XML report and stores the value contained between the end of the left tag (i.e. >) and the beginning of the right tag (i.e. <).
2) Excel searches for the ITEM title tag (the match must be exact).
3) Excel selects the row below the ITEM title tag and moves it down, and inserts the stored ENTITY value to the now empty cell above.
4) Excel continues to do this for all instances of the ITEM tag until it reaches another ENTITY title tag, at which point it loops.
I am thinking I would just need two loops, the ENTITY loop taking priority over the ITEM loop so that it is constantly looking for a new ENTITY. Otherwise I have no idea how it will know to start looking for a new entity.
Any help would be appreciated, thanks!
EDIT:
For reference the XML looks like this:
<Results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Reference>{REFERENCE-HERE}</Reference>
<FillerTags>Filler</FillerTags>
<entity>
<entityName>ABC</entityName>
<entityId>012345</entityId>
</entity>
<Items>
<Item>
<FillerTagsAgain>Filler2</FillerTagsAgain>
<FillerTagsAgain>Filler2</FillerTagsAgain>
<FillerTagsAgain>Filler2</FillerTagsAgain>
</Item>
<AnotherItem>
<FillerTagsAgain>Filler2</FillerTagsAgain>
<FillerTagsAgain>Filler2</FillerTagsAgain>
<FillerTagsAgain>Filler2</FillerTagsAgain>
</AnotherItem>
</Items>
and would be modified to look like this:
<Results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Reference>{REFERENCE-HERE}</Reference>
<FillerTags>Filler</FillerTags>
<entity>
<entityName>ABC</entityName>
<entityId>012345</entityId>
</entity>
<Items>
<Item>
<entityId>012345</entityId>
<FillerTagsAgain>Filler2</FillerTagsAgain>
<FillerTagsAgain>Filler2</FillerTagsAgain>
<FillerTagsAgain>Filler2</FillerTagsAgain>
</Item>
<AnotherItem>
<entityId>012345</entityId>
<FillerTagsAgain>Filler2</FillerTagsAgain>
<FillerTagsAgain>Filler2</FillerTagsAgain>
<FillerTagsAgain>Filler2</FillerTagsAgain>
</AnotherItem>
</Items>
<entity>
.
.
.
I have tried to start by defining some variables and trying to set up a basic structure:
Dim entity As String
Dim item As String
Dim i As Long
Dim j As Long
Dim wb As Workbook
Dim LastEntity As Long
Dim LastItem As Long
LastEntity = Cells.CountIf(Range("A1:A438486")), "<Entity>")
With ActiveSheet
For i = 1 To LastEntity
Cells.Find(What:="ENTITY(i)", After:=ActiveCell, LookIn:=xlFormulas, _
MatchCase:=False, SearchFormat:=False).Activate
For j = 1 To LastItem
The first place I am stuck then is as follows: How do I tell VBA to cycle through all the values that come up when using the 'Find' function. For example, if appears 50 times how do I tell VBA to start with the first entity, then begin the For j = 1 To LastItem
loop? Is the setup above anywhere close to correct?
See Question&Answers more detail:
os