Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
definition of a formula and function? | Excel Discussion (Misc queries) | |||
Extracting Error bar definition | Charts and Charting in Excel | |||
How do you return current ROW number to definition in NAME function? | Setting up and Configuration of Excel | |||
Definition of a statistical function (CQC) in Excel (maybe with VBA...) | Excel Programming | |||
Definition of a statistical function (CQC) in Excel | Excel Worksheet Functions |