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. LOCAL oRange * Last Row/Column *!* lnLastRow = oSheet.UsedRange.Rows.Count *!* lnLastCol = oSheet.UsedRange.Columns.Count #DEFINE xlR1C1 -4150 #DEFINE xlLastCell 11 LOCAL lcOldCarr_Name AS Character, lcYear AS Character lcYear="2010" lcOldCarr_Name = "" 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. IF ALLTRIM(lcCarr_Name) != lcOldCarr_Name && Either first time in, or you have a new carrier. WITH oExcel.ActiveSheet * Put the name of the first report in A1. lcAlphaMonth = LEFT(GetAlphaMonth(nMonth),3) .Cells(lnRow-1,lnCol+3).Value = lcAlphaMonth + " " + lcYear * 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" oRange = .Range("A3:H3").Offset(0, lnColsOffsetToRight) * Move down a row for the new Carrier Name. oRange = oRange.Offset(1,0) .Cells(lnRow-1,lnCol).Value = "Monthly-" + lcCarr_Name ENDWITH ENDIF * This is the Range for the detail data. It spreads from left to right, from * A3 to H3, but it has an offset of 0 rows and lnColsOffSetToRight columns. oRange = oExcel.ActiveSheet.Range("A3:H3").Offset(0, lnColsOffsetToRight) *oxcel.ActiveSheet.Cells(lnRow-1,lnCol).Value = "Monthly-" + lcCarrierName 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) lnRow = lnRow + 1 ENDWITH lcOldCarr_Name = ALLTRIM(&lcCursor..Carr_Name) && Pick up the old Carrier Name. ENDSCAN lnColsOffSetToRight=lnColsOffSetToRight + 9 && Reset to 9 columns to right with OffSet. lnCol = lnColsOffSetToRight + 1 oRange = .Range("A3:H3").Offset(0, lnColsOffSetToRight) && Rest range to 3rd row and offset to right 9 cols. lnRow = 2 && Rest row back to oiriginal place for new month's data. lcOldCarr_Name = "" && Reset this MemVar back to blank. ENDFOR