VBA Error "Object does not support this property or method"

Henry1

New Member
Joined
Oct 23, 2017
Messages
15
hello everyone:

I am a certified excel expert but kind of new to VBA world. I have a simple VBA code but keep getting the error message "Object ......"

Sub test()

ThisWorkbook.Sheets("Henry").Cells(Rows.Count, 1).End(xlUp).Row

End Sub



I have an excel workbook with a worksheet name called Henry. when I run the code why do I get the error message?

thanks for help!

Henry
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hello! This is occurring because you are not telling the code to actually do something. Essentially you are stating an object (The largest row in column 1 with data) but you aren't telling excel to do anything with it. For example, let's say you would like to make column B for that row contain the word "TEST":

Code:
Cells([B]ThisWorkbook.Sheets("Henry").Cells(Rows.Count, 1).End(xlUp).Row[/B], 2) = "TEST"

Another thing you can do is assign that value to a variable and then use it in the future:
Code:
Sub Henry()
Dim LastRow As Long

LastRow = ThisWorkbook.Sheets("Henry").Cells(Rows.Count, 1).End(xlUp).Row

Cells(LastRow, 2) = "Test"

End Sub

I hope this help! If you provide an example of what specifically you are trying to do with that code, we can help you further.
 
Upvote 0
Hi Henry,

Welcome to MrExcel!!

You need to assign a variable to the code you're using to find the last row in Col. A or just display it in a message box. Assuming you want to do something with row number that the code finds try this:

Code:
Option Explicit
Sub test()

    Dim lngLastRow As Long

    lngLastRow = ThisWorkbook.Sheets("Henry").Cells(Rows.Count, 1).End(xlUp).Row
    
    MsgBox lngLastRow

End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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