I have 6 worksheets, each has a subcategory of data (it is important they are in separate worksheets). I am loading up the data into arrays because there are thousands of rows, then printing them out in a specific format to a .txt file.
Sub ExcelToXML()
Dim headers(), data(), attributes1(), attributes2(), attr$, r&, c&
Dim rowCount As Long
Dim columnCount As Long
Dim FF As Worksheet
Dim FOPR As Worksheet
Dim R1 As Long
Dim C1 As Long
Set FF = Worksheets("Fairy")
Set FOPR = Worksheets("Opera")
rowCount = (FF.Range("A1048576").End(xlUp).Row) 'Only one defined as rowCount should be consistent
ffcolumncount = (FF.Range("XFD1").End(xlToLeft).Column)
FOPRcolumnCount = FOPR.Range("XFD1").End(xlToLeft).Column
' load the headers and data to an array '
FFheaders = Cells(1, 1).Resize(1, ffcolumncount).Value
FFdata = Cells(1, 1).Resize(rowCount, ffcolumncount).Value
FOPRheaders = Cells(1, 1).Resize(1, FOPRcolumnCount).Value
FOPRdata = Cells(1, 1).Resize(rowCount, FOPRcolumnCount).Value
' set the size for the attributes based on the columns per child, dynamic
ReDim attributes1(1 To ffcolumncount)
ReDim attributes2(1 To FOPRcolumnCount)
' open file and print the header two main parents
Open "C:\desktop\ToGroup.xml" For Output As #1 'file path is here, going to change to save prompt
Print #1, "<Parent>"
Print #1, " <Child>"
' iterate each row non inclusive of headers
For r = 2 To UBound(FFdata)
' iterate each column '
For c = 1 To UBound(FFdata, 2)
' build each attribute '
attr = FFheaders(1, c) & "=""" & FFdata(r, c) & """"
attributes1(c) = FFheaders(1, c) & "=""" & FFdata(r, c) & """"
Next
For R1 = 2 To UBound(FOPRdata)
For C1 = 1 To UBound(FOPRdata, 2)
attr = FOPRheaders(1, c) & "=""" & FOPRdata(r, c) & """"
attributes2(c) = FOPRheaders(1, c) & "=""" & FOPRdata(r, c) & """"
Next
I cut it off at the prining and at 2 for next loops. (Not actually sure if the for..next loops are structured properly). Anyways, my question is, am I redimensioning wrong? It gives me 'subscript out of range' error on the second attribute. Is the line
ReDim attributes2(1 To FOPRcolumnCount)
the issue? As it may be dimensioning the array in the original worksheet. Perhaps I should define the arrays in separate or worksheet models? Can I and how would I reference them? Is there a way to make the array specifically refer to a worksheet?
Appreciate any input. It's really hard not having anyone around who can provide a second opinion.