I have an xml file to be evaluated in Excel 2010. The xml file looks as follows:
<Account> <Entry> <Value>5</Value> </Entry> <Entry> <Value>4</Value> </Entry> <Entry> <Value>-3.6</Value> </Entry> </Account> I want to sum over all values of every 'Entry' that fits some specified conditions. The evaluation which I need looks as follows:
sum(/*/Entry[Date[starts-with(., '04') and contains(., '2014')]][Value < 0.0][not(ContraEntryID)]/Value) I don't know how to get this evaluated in Excel. What I get so far is a selection where I sum up over every item of it afterwards but there must be a better way to directly get the evaluation right? This is what I have already written:
Private Sub getSumOfValues() Dim xmlFile As String xmlFile = "..." Dim xmlDoc As New MSXML2.DOMDocument60 Dim xmlSelection As IXMLDOMSelection xmlDoc.async = False xmlDoc.validateOnParse = True xmlDoc.Load (xmlFile) xmlDoc.setProperty "SelectionLanguage", "XPath" Set xmlSelection = xmlDoc.SelectNodes("/*/Entry[Date[starts-with(., '04') and contains(., '2014')]][Value < 0.0][not(ContraEntryID)]/Value") Dim i As Integer Dim sum As Double sum = 0 Dim val As String For i = 0 To xmlSelection.Length - 1 val = xmlSelection.Item(i).Text val = Replace(val, ".", ",") sum = sum + CDbl(val) Next i Debug.print(sum) End Sub