lnLastRow is not known to excel, so you have to translate.
Try something like
oExcel.activesheet.Range("D2:D"+TRIM(PADR(lnLastRow,11))).value='=B2+C2'
HTH
Agnes
>Hi,
>I want to set a formula to Column D2 to lnLastRow .
>lnLastRow is no. of rows in the worksheet, how to select the variable range of rows using the .Range method ?
>
>Please advise,
>Derek
>
>
>oExcel = CREATEOBJECT([Excel.Application])
>oWorkbook = oExcel.Workbooks.open("C:\WTS\MID\WTS77XLS.XLS")
>oExcel.Visible = .t.
>oExcel.activesheet.Range("A1").value = "Col. 1"
>oExcel.activesheet.Range("B1").value = "Col. 2"
>oExcel.activesheet.Range("C1").value = "Col. 3"
>oExcel.activesheet.Range("D1").value = "Col. 4"
>oExcel.activesheet.Range("E1").value = "Col. 5"
>
>lnLastRow = oExcel.activesheet.UsedRange.Rows.Count
>
>oExcel.activesheet.Range("D2:lnLastRow").value='=B2+C2'
>
>
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord
Weeks of programming can save you hours of planning.
OffThere is no place like [::1]