ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with Error in Function Definition (https://www.excelbanter.com/excel-programming/420684-help-error-function-definition.html)

RocketDude[_2_]

Help with Error in Function Definition
 
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


Dave Peterson

Help with Error in Function Definition
 
Try:
Public Function GetLastRow(wrksheet As WorkSheet) As Long


RocketDude wrote:

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


--

Dave Peterson

Dave Peterson

Help with Error in Function Definition
 
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")

Dave Peterson wrote:

Try:
Public Function GetLastRow(wrksheet As WorkSheet) As Long

RocketDude wrote:

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


--

Dave Peterson


--

Dave Peterson

RocketDude[_2_]

Help with Error in Function Definition
 
Dave,

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

Cheers,

RocketDude

"Dave Peterson" wrote in message
...
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")

Dave Peterson wrote:

Try:
Public Function GetLastRow(wrksheet As WorkSheet) As Long

RocketDude wrote:

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


--

Dave Peterson


--

Dave Peterson




All times are GMT +1. The time now is 12:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com