.Range("myDataIsland").Columns(1) && 1st column of myDataIsland .Range("myDataIsland").Rows(2) .Range("myDataIsland").Columns(1).Rows(4) && same as .Range("myDataIsland").Cells(4,1) * same size of the island starting 2 rows below and 2 cols right - like cascaded window .Range("myDataIsland").Offset(2,2).Select * A3 is col1,row3 within dataisland. Go 1 row above and 2 columns left and change font color .Range("myDataIsland").Range("A3").Offset(-1,-2).Font.Color = 0x255 .Range("myDataIsland").Cells(3,2).Select && row3,col2 within island .Range("myDataIsland").Range("B2:D10").Select && col2, row2 to col4,row10 within islandetc.
>>Select emp_id,First_Name,Last_Name,Title,Notes ; >> from (Home()+'samples\data\employee') ; >> into Cursor crsToExcel ; >> nofilter >> >>oExcel = Createobject("Excel.Application") >>With oExcel >> .Workbooks.Add >> .Visible = .T. >> With .ActiveWorkBook.ActiveSheet >> .Range('A1:F7000').Cells.Value = 'filled' >> lnStartColumn = 3 && this is xx+1 >> lnColumns = Fcount() >> lcColStart = _GetChar(m.lnStartColumn) && Get Excel column name >> lcColEnd = _GetChar(m.lnStartColumn+m.lnColumns-1) >> lnRowEnd = Reccount()+1 >> lcDataRange = Textmerge('<<m.lcColStart>>1:<<m.lcColEnd>><<m.lnRowEnd>>') >> .Range(Textmerge('<<m.lcColStart>>:<<m.lcColEnd>>')).EntireColumn.Insert >> .Range(m.lcDataRange).Name = "myDataIsland" >> VFP2Excel(oExcel, 'crsToExcel', .Name, "myDataIsland") && Insert data there >> Endwith >>Endwith >> >>* Return A, AA, BC etc noation for nth column >>Function _GetChar >>Lparameters tnColumn && Convert tnvalue to Excel alpha notation >>If tnColumn = 0 >> Return "" >>Endif >>If tnColumn <= 26 >> Return Chr(Asc("A")-1+tnColumn) >>Else >> Return _GetChar(Int(Iif(tnColumn % 26 = 0,tnColumn - 1, tnColumn) / 26)) + ; >> _GetChar((tnColumn-1)%26+1) >>Endif >> >>Function VFP2Excel >>Lparameters toExcel, tcCursorName, tcSheetName, tcRange >>tcCursorName = Iif(Empty(m.tcCursorName),Alias(),m.tcCursorName) >>tcSheetName = Iif(Empty(m.tcSheetName),"Sheet1", m.tcSheetName) >>Local loConn As AdoDB.Connection, loRS As AdoDB.Recordset,; >> lcTempRs, lcTemp, oExcel >>lcTemp = Forcepath(Sys(2015)+'.dbf',Sys(2023)) >>lcTempRs = Forcepath(Sys(2015)+'.rst',Sys(2023)) >>Select (m.tcCursorName) >>Copy To (m.lcTemp) >>loConn = Createobject("Adodb.connection") >>loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+Sys(2023) >>loConn.Open() >>loRS = loConn.Execute("select * from "+m.lcTemp) >>loRS.Save(m.lcTempRs) >>loRS.Close >>loConn.Close >>Erase (m.lcTemp) >>loRS.Open(m.lcTempRs) >> >>With toExcel.WorkSheets( ; >> Iif(Empty(m.tcSheetName),; >> .ActiveWorkBook.ActiveSheet.Name, ; >> m.tcSheetName)) >> .QueryTables.Add( loRS, .Range(m.tcRange)).Refresh() >> .Range(m.tcRange).AutoFormat(8) && xlRangeAutoFormatColor2 >> .Range("A1").Activate >>Endwith >>loRS.Close >>Erase (m.lcTempRs) >>>>PS:ADO part is based on FoxyClasses' dbf2excel class.
Set oRange = oSheet.Columns(xx + 1) >>>oRange.Insert (xlShiftToRight), which did the job nicely compared to cell-by-cell.