Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default IsMissing Function

Function SheetNme(Optional ChkCell As Range = Nothing) As String
On Error GoTo error_handler

If ChkCell Is Nothing Then
SheetNme = Application.Caller.Parent.Name
Exit Function
Else
SheetNme = ChkCell.Parent.Name
End If
Exit Function

error_handler:
MsgBox Err.Number & vbLf & Err.Description

End Function

worked for me.


=================
here is a version with ISMISSING
the argument must be specified as variant to use Ismissing (see Excel vba
help for details)

Function SheetNme(Optional ChkCell As Variant) As String
On Error GoTo error_handler

If IsMissing(ChkCell) Then
SheetNme = Application.Caller.Parent.Name
Exit Function
Else
SheetNme = ChkCell.Parent.Name
End If
Exit Function

error_handler:
MsgBox Err.Number & vbLf & Err.Description

End Function

That worked as well.

--
Regards,
Tom Ogilvy



"mikelee101" wrote:

Hello,
I'm trying to write (what I assumed would be) a relatively simple function.
I want it to return the sheet name of a cell or range included in an argument
or, if no argument is supplied, return the sheet name that the cell is on
that the function resides in. However, I can't seem to make the function
recognize whether the argument has been supplied or not. Here's what I have:

Function SheetNme(Optional ChkCell As Range) As String
On Error GoTo error_handler

If IsMissing(ChkCell) = True Then
SheetNme = ActiveSheet.Name
Exit Function
Else
SheetNme = ChkCell.Worksheet.Name
End If
Exit Function

error_handler:
MsgBox Err.Number & vbLf & Err.Description

End Function

I've also tried IsEmpty, IsNull, IsObject and IsError...none of which make a
distinction between a supplied variable or not.
I tried assigning a value to the variable at declaration, e.g. Optional
ChkCell as Range = ActiveCell.AddressLocal; and various permutations thereof,
but I always got an error that it had to be a constant. Assigning a constant
didn't work well with the range object.

There has to be something that I'm missing, but I couldn't find it in help.
If anyone has any ideas, I'd love the input.

Thanks,
Mike

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
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
IsMissing() Kuzemdoo Dawuni Excel Programming 3 October 15th 04 08:01 PM
IsMissing() Kuzemdoo Dawuni Excel Programming 3 October 15th 04 03:19 AM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 05:59 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"