Now, since we have used lists to gather the data, writing the data out to the Excel spreadsheet doesn't contain a single loop!! How cool is that?!? First, let me explain what some of the other subroutines that you have seen do:
Once we have the sheets setup like we want them, we use the AddStatstoReport sub to populate the sheet. Here is a portion of that sub:
Sub AddStatstoReport
Call AddLine(3,"Total")
Call AddPercentLine(4)
Call AddLine(6,"Company 1")
Call AddLine(7,"Company 2")
Call AddLine(8,"Company 3")
Call AddLine(10,"Mid-Atlantic")
Call AddLine(11,"Midwest")
Call AddLine(12,"Northest")
Call AddLine(13,"Northern California")
Call AddLine(14,"Southeast")
Call AddLine(15,"Southwest")
Call AddLine(16,"West")
Each row is populated by calling the AddLine sub and passing the row number and the identifier. For the second sheet of this report, calling this Sub is done using a ForAll loop and a counter to calculate identifier and row number. Here is what the AddLine sub looks like:
Sub AddLine(row As Integer, listname As String)
If Iselement(statint(listname)) Then xlSheet.cells(row,2).Value = statint(listname) Else xlSheet.cells(row,2).Value = 0
If Iselement(statpass(listname)) Then xlSheet.cells(row,3).Value = statpass(listname) Else xlSheet.cells(row,3).Value = 0
If Iselement(statoffer(listname)) Then xlSheet.cells(row,4).Value = statoffer(listname) Else xlSheet.cells(row,4).Value = 0
If Iselement(statreject(listname)) Then xlSheet.cells(row,5).Value = statreject(listname) Else xlSheet.cells(row,5).Value = 0
If Iselement(stataccept(listname)) Then xlSheet.cells(row,6).Value = stataccept(listname) Else xlSheet.cells(row,6).Value = 0
xlSheet.cells(row,7).FormulaR1C1 = "=if(R" & row & "C2 <> 0,R" & row & "C6/R" & row & "C2,0)"
xlSheet.cells(row,7).NumberFormat = getNumberFormat("Percent")
xlSheet.cells(row,8).FormulaR1C1= "=if(R" & row & "C4,R" & row & "C6/R" & row & "C4,0)"
xlSheet.cells(row,8).NumberFormat = getNumberFormat("Percent")
End Sub
Again, the IsElement function is used to see if the identified exists for each List and, if it does, the value for that identified is retrieved. Since a couple of the cells contain formulas that evaluate out to percentages, we also set the NumberFormat for those cells here. If you have never seen the FormulaR1C1 syntax before, I would suggest getting to know it since it is the easiest way to write Excel formulas from LotusScript.
So there you have it. With a little bit of ingenuity and some efficient coding, you can use Lists and Excel to create some really nice reports that anyone in your company can run. I have posted the code for the Agent in it's entirety for you to dissect at your leisure. Just be nice in your comment as I bruise easily.