0
votes

I want to run a macro named "Lastrow" when the workbook opens, but when opening the workbook the following error occurs:

Compile error: Sub or Function not defined.

Private Sub Workbook_Open()
    Lastrow
End Sub

Autorun code The code that i want to run when the workbook opens the error i am getting when the workbook opens

Note- The vba code "LastRow" is working fine there is no issue only the autorun isnt working

2
where is your LastRow code placed ? regular module ? or worksheet module ? can you share the code there? - Shai Rado
@ShaiRado In this particular case, it's better to use Call for removing ambiguity. - JohnyL
Did you spell it correctly? - JohnyL
Have placed it in worksheet module - j.doe
And the spelling is also correct - j.doe

2 Answers

0
votes

Put your procedure LastRow into a module instead of a worksheet and declare it

Public Sub LastRow()

Then you can use it like

Private Sub Workbook_Open()
    LastRow
End Sub
-1
votes

You have to be explicit, for instance, if the procedure LastRow is in Module1, you have to write Module1.LastRow.