Using a sub created in module1 in different modules

kklewis

New Member
Joined
Dec 5, 2005
Messages
17
I created a sub in one module with the following code:

Public Sub lastrow(start As Integer, col As Integer, last As Integer)
i = start
Do
i = i + 1
currentcell = Cells(i, col)
Loop Until IsEmpty(currentcell)
last = i - 1
End Sub

When I call the sub in the current module using the code -
Call lastrow (5, 1, lcr)
it works fine and i create a variable lcr with an integer value. However, when I open another module and run the same code I get an error message "Ambiguous name detected: lastrow"

Any suggestions?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
This is not my area of expertise

but let me give it a bump while taking my best shot at the answer:

It sounds like the name "lastRow" is in more than one place. You didn't paste the Sub in the second module did you? Or have a variable named "lastRow"?

I'm self-taught; so, I don't know the formalities of a lot of stuff, but I know that I can call subs in a module from another module. So, I read your error message to indicate that you have 2 different "lastRows" in your project. You can use Edit\Find in the VBA Editor to look for all occs. of "lastRow" and see if I'm right or not.

Maybe that helps, my best shot from what you said. Bump.
 
Upvote 0
If you do not have the general declaration of "Option Explicit" you will be able to use the same variable name in multiple modules.

BK is right, the only way to get this error is if you had last row declared in a concurrently executing subroutine.
 
Upvote 0

Forum statistics

Threads
1,217,437
Messages
6,136,615
Members
450,022
Latest member
Joel1122331

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