How to get the row number of a row

luolovepi

Board Regular
Joined
Jun 9, 2011
Messages
116
Code:
desLastRow.Row <> desSheet.Cells(desSheet.Rows.count, "F").End(xlUp).Row
I want to compare the row number of the two sides. But it result in a problem that the left side requires object. What's wrong with this line?
note: desLastRow is a range indicates the last row having contents. desSheet is a worksheet.

Best regards,
lolo^^
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Can you show us some more code, specifically your Dim statement for the desLastRow variable and the statement where you assign a value to the desLastRow variable (also, some of the code surrounding them might help us also).
 
Upvote 0
Hi Rick,

My code is really long. Hard to copy to here. The declaration and assignment of desLastRow is as follows:
Code:
Public desLastRow As Range 
desLastRow = desSheet.Cells(desSheet.Rows.count, "F").End(xlUp)
Actually I have another line of code whic is similar to the error line but is correct:
Code:
this = desLastRow.Row

Thanks!

Best regards,
lolo
Can you show us some more code, specifically your Dim statement for the desLastRow variable and the statement where you assign a value to the desLastRow variable (also, some of the code surrounding them might help us also).
 
Last edited:
Upvote 0
Are you running any On Error Resume Next statements? I ask because this line...
Code:
desLastRow = desSheet.Cells(desSheet.Rows.count, "F").End(xlUp)
should be raising an error. Since desLastRow is declared as a Range variable, you need to use Set to assign a range to it...
Code:
Set desLastRow = desSheet.Cells(desSheet.Rows.count, "F").End(xlUp)
Also, the error message you reported to us indicates that at that point in your code, it does not see desLastRow as a Range object. Perhaps there is a scope issue at work here. What module is the Public declaration of desLastRow in and what module is the error occurring at?
 
Upvote 0
Hi Rick,

Thanks for your help!
I solved the problem by changing the value of a variable, since I forgot to change its value. Very strangely, I don't understand how that value is related to this error...

And do you happen to know the following:
Code:
Set des = Application.Workbooks.Open(desPathName, True, False)
        On Error GoTo browse
How come when there's a error when opening the file, the code does not go to 'browse' to run the code there?



Are you running any On Error Resume Next statements? I ask because this line...
Code:
desLastRow = desSheet.Cells(desSheet.Rows.count, "F").End(xlUp)
should be raising an error. Since desLastRow is declared as a Range variable, you need to use Set to assign a range to it...
Code:
Set desLastRow = desSheet.Cells(desSheet.Rows.count, "F").End(xlUp)
Also, the error message you reported to us indicates that at that point in your code, it does not see desLastRow as a Range object. Perhaps there is a scope issue at work here. What module is the Public declaration of desLastRow in and what module is the error occurring at?
 
Upvote 0
And do you happen to know the following:
Code:
Set des = Application.Workbooks.Open(desPathName, True, False)
        On Error GoTo browse
How come when there's a error when opening the file, the code does not go to 'browse' to run the code there?
The On Error statement should go before the line of code you anticipate might raise an error. Try reversing the two statements you posted.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,672
Members
452,937
Latest member
Bhg1984

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