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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

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,122,530
Messages
5,596,699
Members
414,088
Latest member
rodriboraun

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
Top