#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default UDF

A long time ago someone gave me this UDF which has been of great value to
me.

Function myCell(Optional Cell)
Application.Volatile
If IsMissing(Cell) Then
myCell = Application.Caller. _
Address(rowabsolute:=False, _
columnabsolute:=False)
Else
myCell = Cell. _
Address(rowabsolute:=False, _
columnabsolute:=False)
End If
End Function

If I type for example: =mycell(K353) returns K353. If I type =mycell($K$353)
it still returns K353.

Question:
What should the UDF look like if I want:

=mycell(K353;1) should return K353
=mycell(K353;2) should return $K353
=mycell(K353;3) should return K$353
=mycell(K353;4) should return $K$353

Hans Knudsen

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default UDF

Function myCell(Optional Cell, optional Style = 1)
Application.Volatile
If IsMissing(Cell) Then
myCell = Application.Caller. _
Address(rowabsolute:=False, _
columnabsolute:=False)
Else

columnStyle = (Style Mod 2 = 0)
rowStyle = Style 2

myCell = Cell. _
Address(rowabsolute:=rowStyle, _
columnabsolute:=columnStyle)
End If
End Function


"Hans Knudsen" wrote:

A long time ago someone gave me this UDF which has been of great value to
me.

Function myCell(Optional Cell)
Application.Volatile
If IsMissing(Cell) Then
myCell = Application.Caller. _
Address(rowabsolute:=False, _
columnabsolute:=False)
Else
myCell = Cell. _
Address(rowabsolute:=False, _
columnabsolute:=False)
End If
End Function

If I type for example: =mycell(K353) returns K353. If I type =mycell($K$353)
it still returns K353.

Question:
What should the UDF look like if I want:

=mycell(K353;1) should return K353
=mycell(K353;2) should return $K353
=mycell(K353;3) should return K$353
=mycell(K353;4) should return $K$353

Hans Knudsen


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default UDF

Maybe this

You have to put the non-optional argument first

=mycell(1,A1)
or Mycell(1)

Function myCell(mytype As Integer, Optional Cell)
If mytype 4 Then myCell = "Error": Exit Function
Application.Volatile
If IsMissing(Cell) Then
Select Case mytype
Case Is = 1
myCell = Application.Caller.Address(rowabsolute:=False,
columnabsolute:=False)
Case Is = 2
myCell = Application.Caller.Address(rowabsolute:=False,
columnabsolute:=True)
Case Is = 3
myCell = Application.Caller.Address(rowabsolute:=True,
columnabsolute:=False)
Case Is = 4
myCell = Application.Caller.Address(rowabsolute:=True,
columnabsolute:=True)

End Select
Else

Select Case mytype
Case Is = 1
myCell = Cell.Address(rowabsolute:=False, columnabsolute:=False)

Case Is = 2
myCell = Cell.Address(rowabsolute:=False, columnabsolute:=True)

Case Is = 3
myCell = Cell.Address(rowabsolute:=True, columnabsolute:=False)

Case Is = 4
myCell = Cell.Address(rowabsolute:=True, columnabsolute:=True)
End Select
End If
End Function


Mike


"Hans Knudsen" wrote:

A long time ago someone gave me this UDF which has been of great value to
me.

Function myCell(Optional Cell)
Application.Volatile
If IsMissing(Cell) Then
myCell = Application.Caller. _
Address(rowabsolute:=False, _
columnabsolute:=False)
Else
myCell = Cell. _
Address(rowabsolute:=False, _
columnabsolute:=False)
End If
End Function

If I type for example: =mycell(K353) returns K353. If I type =mycell($K$353)
it still returns K353.

Question:
What should the UDF look like if I want:

=mycell(K353;1) should return K353
=mycell(K353;2) should return $K353
=mycell(K353;3) should return K$353
=mycell(K353;4) should return $K$353

Hans Knudsen


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default UDF

Hi Hans - try this amendment -

Option Explicit

Function myCell(Optional Cell, Optional My_Type As Integer = 1)
Dim My_Row As Boolean, My_Col As Boolean

My_Row = (My_Type = 3) Or (My_Type = 4)
My_Col = (My_Type = 2) Or (My_Type = 4)

Application.Volatile
If IsMissing(Cell) Then
myCell = Application.Caller. _
Address(rowabsolute:=My_Row, _
columnabsolute:=My_Col)
Else
myCell = Cell. _
Address(rowabsolute:=My_Row, _
columnabsolute:=My_Col)
End If
End Function

Regards,
Muppet Man.


On Sep 29, 1:26*pm, "Hans Knudsen" wrote:
A long time ago someone gave me this UDF which has been of great value to
me.

Function myCell(Optional Cell)
Application.Volatile
* * If IsMissing(Cell) Then
* * * * myCell = Application.Caller. _
* * * * * * Address(rowabsolute:=False, _
* * * * * * columnabsolute:=False)
* * Else
* * * * myCell = Cell. _
* * * * * * Address(rowabsolute:=False, _
* * * * * * columnabsolute:=False)
* * End If
End Function

If I type for example: =mycell(K353) returns K353. If I type =mycell($K$353)
it still returns K353.

Question:
What should the UDF look like if I want:

=mycell(K353;1) should return K353
=mycell(K353;2) should return $K353
=mycell(K353;3) should return K$353
=mycell(K353;4) should return $K$353

Hans Knudsen


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



All times are GMT +1. The time now is 09:38 AM.

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

About Us

"It's about Microsoft Excel"