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?
 

Some videos you may like

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

bk

Active Member
Joined
Jun 2, 2002
Messages
387
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.
 

XLGibbs

Well-known Member
Joined
Feb 25, 2005
Messages
2,446
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,817
Messages
5,574,499
Members
412,598
Latest member
Haven1234
Top