I'm working on taking some input data in excel, parsing it to xml and using that to run a SQL stored procedure, but I'm running into performance issue on the xml parsing. The input sheet looks something like this:
Dates_|_Name1_Name2_Name3_..._NameX
Date1 |
Date2 |
. . . |
Date1Y|
I've got some code to loop though each cell and parse out the data into an xml string but even for about a 300 by 300 grid the execution takes something on the order of five minutes and I'm looking to use data sets that could be several thousand columns long. I've tries a couple things to help speed it up like reading the data into a Variant then iterating though that or excluding DoEvents but I haven't been able to get the speed up. Here's the bit of code that's the issue:
Dim lastRow As Long
lRows = (oWorkSheet.Cells(Rows.Count, 1).End(xlUp).Row)
Dim lastColumn As Long
lCols = (oWorkSheet.Cells(1, Columns.Count).End(xlToLeft).Column)
Dim sheet As Variant
With Sheets(sName)
sheet = .Range(.Cells(1, 1), .Cells(lRows, lCols))
End With
ReDim nameCols(lCols) As String
...
resultxml = "<DataSet>"
For i = 2 To rows
resultxml = resultxml & "<DateRow>"
For j = 1 To cols
If Trim(sheet(i, j)) <> "" Then
lResult = "<" & nameCols(j) & ">"
rResult = "</" & nameCols(j) & ">"
tmpValue = Trim(sheet(i, j))
If IsDate(tmpValue) And Not IsNumeric(tmpValue) Then
If Len(tmpValue) >= 8 Then
tmpValue = Format(tmpValue, "yyyy-mm-dd")
End If
End If
resultxml = resultxml & lResult & tmpValue & rResult
DoEvents
End If
Next j
resultxml = resultxml & "</DateRow>"
Next i
resultxml = resultxml & "</DataSet>"
Any advice for getting the run time down would be greatly appreciated.