Help with Error in Function Definition

R

RocketDude

Hi,

I have a function in my module (see code below) that when I try and compile
the module gives me the following compile error:
"User-defined type not defined"

Function Code:
---------------------
Public Function GetLastRow(wrksheet As Sheet) As Long
' Use this function to find the last row (number) used
Dim rng As Range
Dim LastRow As Long

'Use a range on the sheet
Set rng = Sheets(wrksheet).Range("B5:B500")

' Find the last row
LastRow = Last(1, rng)
GetLastRow = LastRow

End Function
---------------------------

I cannot figure out what's wrong with the above function declaration. Does
anyone have a suggestion of what I'm doing wrong?

Thanks,

RocketDude
 
D

Dave Peterson

Actually, you probably want:

Public Function GetLastRow(wrksheet As String) As Long
since you use:
Set rng = Sheets(wrksheet).Range("B5:B500")


But you could use "as Worksheet" if you used this:

Public Function GetLastRow(wrksheet As WorkSheet) As Long
Set rng = wrksheet.Range("B5:B500")
 
R

RocketDude

Dave,

Thank you -- setting wrksheet to string solved my problem.

Cheers,

RocketDude
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top