I missed the part about Groups of 10 so try this
Function ColumnNumberToLetters(ColumnNumber As Long) As String
Dim strLetters As String
strLetters = Cells(1, ColumnNumber).Address(1, 0)
ColumnNumberToLetters = Left(strLetters, InStr(1, strLetters, "$") - 1)
End Function
Private Sub ExportToXML()
On Error GoTo ErrorHandler
Const sFullPathName As String = "C:\Users\Mike\Desktop\text.xml"
Const shName As String = "6pm"
Const sTableName As String = "Items"
Const RowName As String = "Item"
Dim oWorkSheet As Worksheet
Dim lCols As Long, lRows As Long, i As Long, j As Long
Dim iFileNum As Integer
Dim str As String
Dim iMod As Long
Set oWorkSheet = ThisWorkbook.Worksheets(shName)
iFileNum = FreeFile
Open sFullPathName For Output As #iFileNum
Print #iFileNum, "<?xml version=""1.0"" encoding=""utf-8""?>"
Print #iFileNum, "<" & sTableName & ">"
With oWorkSheet
lRows = .Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lCols = .Cells.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
For i = 1 To lRows
If iMod = 10 Then
Print #iFileNum, "</" & sTableName & ">"
Print #iFileNum, "<" & sTableName & ">"
iMod = 0
End If
iMod = iMod + 1
Print #iFileNum, vbTab & "<" & RowName & ">"
For j = 1 To lCols
str = ColumnNumberToLetters(j)
If Trim(.Cells(i, j).Value) <> "" Then
Print #iFileNum, vbTab & vbTab & "<" & str & ">";
Print #iFileNum, Trim(.Cells(i, j).Value);
Print #iFileNum, "</" & str & ">"
End If
Next j
Print #iFileNum, vbTab & "</" & RowName & ">"
Next i
End With
Print #iFileNum, "</" & sTableName & ">"
Set oWorkSheet = Nothing
ErrorHandler:
If iFileNum > 0 Then Close #iFileNum
Exit Sub
End Sub
Bookmarks