View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default CurrentRegion works different in the Editor than in the workbook

Hi Miguel,

Unfortunately, the CurrentRegion property cannot be used successfully in a
UDF.

In a similar way, the SpecialCells method does not work correctly in a
worksheet function.


---
Regards,
Norman



"Miguel Zapico" wrote in message
...
Hi all,

I have tried to use CurrentRegion to define a range, and it doesn't work
in
the workbook, but works in the editor. I have used it on a function, and
the
function doesn't get the right region when called from the worksheet, but
it
does from the Inmediate window.
This is the function:

Function Test()
Dim rngData As Excel.Range
Set rngData =
ActiveWorkbook.Worksheets("Sheet1").Range("A1").Cu rrentRegion
Test = rngData.Rows.Count
End Function

I have a region of 2 columns and 12 rows in A1 of sheet1, if I try the
function in the inmediate window with ?Test(), it returns 12; If I use it
on
the workbook with =Test(), it returs 1.
The version of Excel is 2003 SP1. Is there anything that I am doing
wrong?
I would like to know why it doesn't work.

Miguel.