Object Defined Error

tourless

Board Regular
Joined
Feb 8, 2007
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hi Folks,

I'm not sure why the following line of code fails...

wsCustomerReportCard.Cells(10, LastRow(wsCustomerReportCard)).FormulaR1C1 = "=(8, LastRow(wsCustomerReportCard))-(9, LastRow(wsCustomerReportCard)"

I'm simply trying to subtract with a last row reference as this included in a loop.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
What is "LastRow"?
Is it a User Defined Function you have created?
If so, what does that code look like?

Also, this does not look to be a valid formula:
Code:
[COLOR=#333333]=(8, LastRow(wsCustomerReportCard))-(9, LastRow(wsCustomerReportCard)[/COLOR]
 
Upvote 0
What is "LastRow"?
Is it a User Defined Function you have created?
If so, what does that code look like?
Yes, it's a function...
Code:
Function LastRow(targetSheet As Worksheet, Optional targetCol As String = "A")

    With targetSheet
        LastRow = .Cells(.Rows.Count, targetCol).End(xlUp).row
    End With

End Function

While I've been waiting I've also tried making a local lRow as long and loading it's value from LastRow...
Code:
lRow = LastRow(wsCustomerReportCard)
then tried..
Code:
wsCustomerReportCard.Range("H" & lRow).Formula = "=F & lRow &- & G & lRow"
still no dice, same error. pretty sure it's a syntax error.
 
Last edited:
Upvote 0
What are 8 and 9 in the formula meant to be?

Does this work?
Code:
wsCustomerReportCard.Cells(10, LastRow(wsCustomerReportCard)).FormulaR1C1 = "=RC8-RC9"
 
Upvote 0
8 and 9 were meant to be column references and yes that worked perfectly. Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top