View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Priyanka Priyanka is offline
external usenet poster
 
Posts: 4
Default Error Application Defined or Object Defined

Hi

Was trying to write a macro to insert a formula in a range of cells. The
last cell is calculated using the function Lastrow. However when i run it, I
get the following error:
"Application-defined or Object-defined error"
This is the macro.

Sub Max_range_calc()

' Keyboard Shortcut: Ctrl+Shift+M
Dim i, k As Integer
k = LastRow(7)
For i = 1 To k
Cells(i, 7).FormulaR1C1 = "=(RC[-2]-RC[-3])/RC[-1]"
Next i
End Sub

Function LastRow(C)
R = 10000 'set R to be greater than your maxim row number
Do
If (Cells(R, C)) < "" Then Exit Do Else R = R - 1
Loop
LastRow = R
End Function

Please Help!!!
Thanks a bunch

Priyanka