Bug: method or data member not found!

luolovepi

Board Regular
Joined
Jun 9, 2011
Messages
116
I have a statement in a sub of a module like this:
desLastRowNumber = ActiveSheet.Cells(.Rows.count, "F").End(xlUp).Row
Call ActiveSheet.Boxes(desLastRowNumber)


AND "Public Sub Boxes(newRow As Long)" is declared in another module

When I run my program, I get the error stating that: method not found!

What's wrong with my code?
Anyone can help me? Thank you!!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Shouldn't it be

Code:
desLastRowNumber = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row

No . in front of Cells.
 
Upvote 0
Hi VoG,

Thanks! But I think that's not the problem. Part of my sub1 code in module1 is actually like this:
With desSheet
Dim desLastRow As Range
Set desLastRow = .Cells(.Rows.count, "F").End(xlUp)
desLastRowNumber = desLastRow.Row
desLastRowNumber = desLastRowNumber + 1
Call .Boxes(desLastRowNumber)
End With

the declaration of Boxes in Module2:
Public Sub Boxes(newRow As Long)

Isn't it correct?


Shouldn't it be

Code:
desLastRowNumber = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row

No . in front of Cells.
 
Upvote 0
I'm so sorry, here is a copy of a more complete code:
sub1 code in module1 is actually like this:
With desSheet
Dim desLastRow As Range
Dim desLastRowNumber As Long
Set desLastRow = .Cells(.Rows.count, "F").End(xlUp)
desLastRowNumber = desLastRow.Row
desLastRowNumber = desLastRowNumber + 1
Call .Boxes(desLastRowNumber)
End With

the declaration of Boxes in Module2:
Public Sub Boxes(newRow As Long)

Shouldn't it be

Code:
desLastRowNumber = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row

No . in front of Cells.
 
Upvote 0
Incorrect. When you type . before Boxes, it belongs to desSheet.
Here's correct:
Code:
With desSheet
    Call Module2.Boxes(.Cells(.Rows.count, "F").End(xlUp).Row + 1)
End With
 
Last edited:
Upvote 0
This works for me

Code:
Sub test()
Dim desLastRow As Range
Dim desLastRowNumber As Long
Dim desSheet As Worksheet
Set desSheet = ActiveSheet
With desSheet
    Set desLastRow = .Cells(Rows.Count, "F").End(xlUp)
    desLastRowNumber = desLastRow.Row
    desLastRowNumber = desLastRowNumber + 1
    Call Boxes(desLastRowNumber)
End With
End Sub

Public Sub Boxes(newRow As Long)
MsgBox newRow
End Sub
 
Upvote 0
WOW!! You are right!
Thank you SO MUCH!!!
And one more question to ask:
In the module2 Boxes(newRow as Long) sub, I have:
Cells(newRow, 1)

Is it correct to put a Long type parameter in Cells()?

Rgds,
Lolo

Incorrect. When you type . before Boxes, it belongs to desSheet.
Here's correct:
Code:
Dim desLastRowNumber As Long
 
With desSheet
    desLastRowNumber = .Cells(.Rows.count, "F").End(xlUp).Row
    desLastRowNumber = desLastRowNumber + 1
    Call Module2.Boxes(desLastRowNumber)
End With
 
Upvote 0
Absolutely.
And you can avoid variables with this short code:
Code:
With desSheet
    Call Module2.Boxes(.Cells(.Rows.count, "F").End(xlUp).Row + 1)
End With
 
Upvote 0
yeah, I got it!
Thank you very much!

rdgs,
lolo
This works for me

Code:
Sub test()
Dim desLastRow As Range
Dim desLastRowNumber As Long
Dim desSheet As Worksheet
Set desSheet = ActiveSheet
With desSheet
    Set desLastRow = .Cells(Rows.Count, "F").End(xlUp)
    desLastRowNumber = desLastRow.Row
    desLastRowNumber = desLastRowNumber + 1
    Call Boxes(desLastRowNumber)
End With
End Sub
 
Public Sub Boxes(newRow As Long)
MsgBox newRow
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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