Works in a Sub, but Fails as a Function. Anyone know why?

So, This works fine. If there are 194 rows used, then it returns 194:
Sub ShowMeLastRow()
 Dim lLastRow As Long
 ' Define the number of the bottom row
 lLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 ' Send the last row's number back
 MsgBox lLastRow
End Sub

However, this just gives me an error:
Sub ShowMeLastRow()
 MsgBox fLastRowNumber
End Sub
Function fLastRowNumber()
 Dim lLastRow As Long
 ' Define the number of the bottom row
 lLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 ' Send the last row's number back
 LastRowNumber = lLastRow
End Function

The error I get is:
Run-time error '1004':
Method 'Range' of object '_Global' failed

Probably something stupid, but my brain's fried as is, so I'm not seeing it :(

Thanks in advance.
VriaelissAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

g_johnsonCommented:
function fLastRowNumber() as Long
VriaelissAuthor Commented:
Thanks for the quick response. It fixed part of the problem, but I'm still getting that error in this code specifically, even with that change:

Sub FillOutFormulae()
    Dim sStop As String
    ' Fill down the Column A formula "ProgInfo"
    Range("A2").Copy Range("A5")
    Application.CutCopyMode = False
    sStop = "A5:A" & fLastRowNumber
    Range("A5").AutoFill Destination:=Range(sStop)****Error happens here****
...
End Sub

g_johnsonCommented:
so this is a different question now?
I'm assuming this is Excel VBA -- i'll see if I can figure out the syntax for that line.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

g_johnsonCommented:
this worked fine for me:


Private Sub CommandButton1_Click()

    Dim sStop As String
    ' Fill down the Column A formula "ProgInfo"
    Range("A2").Copy Range("A5")
    Application.CutCopyMode = False
    sStop = "A5:A" & fLastRowNumber
    Range("A5").AutoFill Destination:=Range(sStop) '****Error happens here****


End Sub
Function fLastRowNumber() As Long
 Dim lLastRow As Long
 ' Define the number of the bottom row
 lLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 ' Send the last row's number back
 fLastRowNumber = lLastRow
End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Data DudeCommented:
As g_johnson commented above, you have a function named fLastRowNumber, and in the code you are setting {hey looky here, no 'f'}LastRowNumber = lLastRow

VriaelissAuthor Commented:
I meant to split points... getting mods to re-open question so I can :)

Thanks to both of you. It works now. (Gotta love typos xP)
Jim HornMicrosoft SQL Server Data DudeCommented:
Thanks for the split.  Good luck with your project.  -Jim
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.