Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
definition of a formula and function? showsomeidnow[_2_] Excel Discussion (Misc queries) 6 May 6th 07 09:40 AM
Extracting Error bar definition Barb Reinhardt Charts and Charting in Excel 3 January 24th 07 02:48 PM
How do you return current ROW number to definition in NAME function? Franz Verga Setting up and Configuration of Excel 1 July 24th 06 04:13 PM
Definition of a statistical function (CQC) in Excel (maybe with VBA...) uriel78 Excel Programming 5 March 8th 05 06:03 PM
Definition of a statistical function (CQC) in Excel uriel78 Excel Worksheet Functions 0 March 2nd 05 07:30 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"