Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default SpecialCells in UDF

Hi Friends

I have an UDF accepting "anything" as input, it is using the numerical
stuff. A simplified demo:

Public Function myFunction(ParamArray vals() As Variant) As String
Dim L As Long
Dim Cel As Range
Dim FilledCells As Range

For L = LBound(vals) To UBound(vals)
If TypeName(vals(L)) = "Range" Then
On Error Resume Next
Set FilledCells = _
Union(vals(L).SpecialCells(xlCellTypeConstants, 1), _
vals(L).SpecialCells(xlCellTypeFormulas, 1))
On Error GoTo 0
If Not FilledCells Is Nothing Then _
myFunction = myFunction & FilledCells.Address & " "
Set FilledCells = Nothing
'Else stuff here
End If
Next
End Function

The Union statement resizes the range to use only number constants and
numeric formula results, improving performance a lot when ranges are big.
And here is the part I don't get:

Called from code the filled cells assign beautifully:

Sub test()
MsgBox myFunction(Sheets(1).Range("A1:B100"))
End Sub

but called from a cell it does nothing.
=myFunction(A1:B100)
returns A1:B100. Meaning that the Set statement works, but not the
specialcells extraction.

Is this a known issue ? Or am I missing something ovious ?

Best wishes Harald

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

Or am I missing something obvious ?

Yes<g. A worksheet-called UDF cannot "take actions" and SpecialCells is
unfortunately an action.

--
Jim
"Harald Staff" wrote in message
...
Hi Friends

I have an UDF accepting "anything" as input, it is using the numerical
stuff. A simplified demo:

Public Function myFunction(ParamArray vals() As Variant) As String
Dim L As Long
Dim Cel As Range
Dim FilledCells As Range

For L = LBound(vals) To UBound(vals)
If TypeName(vals(L)) = "Range" Then
On Error Resume Next
Set FilledCells = _
Union(vals(L).SpecialCells(xlCellTypeConstants, 1), _
vals(L).SpecialCells(xlCellTypeFormulas, 1))
On Error GoTo 0
If Not FilledCells Is Nothing Then _
myFunction = myFunction & FilledCells.Address & " "
Set FilledCells = Nothing
'Else stuff here
End If
Next
End Function

The Union statement resizes the range to use only number constants and
numeric formula results, improving performance a lot when ranges are big.
And here is the part I don't get:

Called from code the filled cells assign beautifully:

Sub test()
MsgBox myFunction(Sheets(1).Range("A1:B100"))
End Sub

but called from a cell it does nothing.
=myFunction(A1:B100)
returns A1:B100. Meaning that the Set statement works, but not the
specialcells extraction.

Is this a known issue ? Or am I missing something ovious ?

Best wishes Harald



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default SpecialCells in UDF

Thanks Jim, I feared that it was the "can not change environment"
limitation. In this case it doesn't make any sense to me. But maybe the
specialcells has some huge powers that I'm not yet aware of <bg.

Best wishes Harald

"Jim Rech" wrote in message
...
Or am I missing something obvious ?


Yes<g. A worksheet-called UDF cannot "take actions" and SpecialCells is
unfortunately an action.

--
Jim
"Harald Staff" wrote in message
...
Hi Friends

I have an UDF accepting "anything" as input, it is using the numerical
stuff. A simplified demo:

Public Function myFunction(ParamArray vals() As Variant) As String
Dim L As Long
Dim Cel As Range
Dim FilledCells As Range

For L = LBound(vals) To UBound(vals)
If TypeName(vals(L)) = "Range" Then
On Error Resume Next
Set FilledCells = _
Union(vals(L).SpecialCells(xlCellTypeConstants, 1), _
vals(L).SpecialCells(xlCellTypeFormulas, 1))
On Error GoTo 0
If Not FilledCells Is Nothing Then _
myFunction = myFunction & FilledCells.Address & " "
Set FilledCells = Nothing
'Else stuff here
End If
Next
End Function

The Union statement resizes the range to use only number constants and
numeric formula results, improving performance a lot when ranges are big.
And here is the part I don't get:

Called from code the filled cells assign beautifully:

Sub test()
MsgBox myFunction(Sheets(1).Range("A1:B100"))
End Sub

but called from a cell it does nothing.
=myFunction(A1:B100)
returns A1:B100. Meaning that the Set statement works, but not the
specialcells extraction.

Is this a known issue ? Or am I missing something ovious ?

Best wishes Harald




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
How are these uses of SpecialCells different? M. Authement Excel Programming 0 May 28th 07 08:16 PM
SpecialCells Value=0?? Otto Moehrbach Excel Programming 2 December 9th 06 02:23 PM
SpecialCells mike Excel Programming 4 June 8th 06 01:50 AM
SpecialCells Peter Excel Programming 3 April 12th 06 02:03 PM
Specialcells Bruno Uato Charts and Charting in Excel 0 October 7th 05 07:42 PM


All times are GMT +1. The time now is 04:34 PM.

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"