SET EXACT ON RELEASE ALL LIKE o* PUBLIC oExcel CLEAR ALL USE c:\dev\tmpNearly01 IN 0 USE c:\dev\tmpNearly02 IN 0 USE c:\dev\tmpNearly03 IN 0 USE c:\dev\tmpNearly04 IN 0 USE c:\dev\tmpNearly05 IN 0 USE c:\dev\tmpNearly06 IN 0 USE c:\dev\tmpNearly07 IN 0 USE c:\dev\tmpNearly08 IN 0 USE c:\dev\tmpNearly09 IN 0 USE c:\dev\tmpNearly10 IN 0 USE c:\dev\tmpNearly11 IN 0 USE c:\dev\tmpNearly12 IN 0 * Create the Spreadsheet object. oExcel = CREATEOBJECT("Excel.Application") oExcel.Visible = .T. oWorkBook = oExcel.WorkBooks.Add() oSheet = oWorkBook.ActiveSheet lnColsOffsetToRight= 0 lnRow = 2 && Start with Column Headings on Row 2. lnCol = 1 && Start in Column 1. lnRowOffSet = 0 lcFirstTimeCarrier = 0 LOCAL oRange #DEFINE xlR1C1 -4150 #DEFINE xlLastCell 11 LOCAL lcOldCarr_Name AS Character, lcYear AS Character lcYear="2010" lcOldCarr_Name = SPACE(1) SET STEP ON lnMonths=12 FOR nMonth = 1 TO lnMonths * Select the correct Month's cursor (table). lcMonth=PADL(nMonth, 2, "0") lcCursor=("tmpNearly"+lcMonth) SELECT (lcCursor) SCAN lcCarr_Name = ALLTRIM(&lcCursor..Carr_Name) && Pick up the new Carrier Name. oRange = oExcel.ActiveSheet.Range("A3:H3").Offset(lnRowOffset, lnColsOffsetToRight) * If this is the first time in, lnRow equals row 2. IF ALLTRIM(lcCarr_Name) != lcOldCarr_Name && Either first time in, or you have a new carrier. lcFirstTimeCarrier = lcFirstTimeCarrier + 1 IF lcFirstTimeCarrier > 1 lnRowOffSet = 4 ENDIF oRange = oExcel.ActiveSheet.Range("A3:H3").Offset(lnRowOffset, lnColsOffsetToRight) WITH oExcel.ActiveSheet * Put the name of the first report in A1. lcAlphaMonth = LEFT(GetAlphaMonth(nMonth),3) * The following code is only executed once per month's data. .Cells(lnRow-1,lnCol).Value = "Monthly-" + lcCarr_Name && Carrier Name. .Cells(lnRow-1,lnCol+3).Value = lcAlphaMonth + " " + lcYear && Month and Year. * Lay out the Columnn Headings from Left to Right. .Cells(lnRow, lnCol).Value = "Group Name" .Cells(lnRow, lnCol + 1).Value = "GrpID" .Cells(lnRow, lnCol + 2).Value = "Emp. ID" .Cells(lnRow, lnCol + 3).Value = "Benefit" .Cells(lnRow, lnCol + 4).Value = "Month_Billed" .Cells(lnRow, lnCol + 5).Value = "Month_Collected" .Cells(lnRow, lnCol + 6).Value = "Annualized Premium" .Cells(lnRow, lnCol + 7).Value = "Lives" ENDWITH * Move down a row for the new Carrier Name. *oRange = oRange.Offset(1,0) ENDIF WITH oRange * Print the columns/fields to the page. This runs left to right on the default row. .Columns[1].Value = GrpName && Group Name .Columns[2].Value = GrpID && Group ID .Columns[3].Value = Emp_ID && Employer's ID .Columns[4].Value = Benefit && Benefit Name. .Columns[5].Value = Billed && Monthly Billed Amount By GrpID, Employer. .Columns[6].Value = Collected && Monthly Collected amount by GrpID, Employer. .Columns[7].Value = Annualized && Annualized Premium. .Columns[8].Value = Lives && # of Primary Insured. * Move down one row. oRange = oRange.Offset(1,0) ENDWITH lcOldCarr_Name = ALLTRIM(&lcCursor..Carr_Name) && Pick up the old Carrier Name. ENDSCAN * Reset everything. Going to a new month. lcFirstTimeCarrier = 0 lnColsOffSetToRight=lnColsOffSetToRight + 9 && Reset to 9 columns to right with OffSet. lnCol = lnColsOffSetToRight + 1 && This leaves a blank column between each month's data. oRange = oExcel.ActiveSheet.Range("A3:H3").Offset(0, lnColsOffSetToRight) && Reset range to 3rd row and offset to right 9 cols. lnRow = 2 && Rest row back to oiriginal place for new month's data. lnRowOffSet = 0 && Reset Row OffSet to 0. lcOldCarr_Name = SPACE(1) && Reset this MemVar back to blank. ENDFOR