Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default range.find method called into a VBA function (problem)

I have a problem using the find method of range object. It works fine if I
use into a Sub procedure; but fails (i.e. return nothing all time) if I use
it into a Function.
Image I have the following excel column (A1:A4):
10
20
30
40

the following sub is ok (the messagebox show A2):
Sub FindTest()
Dim R as Range
Dim C as Range
Set R = ActiveSheet.Range("A:A")
Set C = R.Find(20,,xlValues)
MsgBox C.Address
End

but the following function desn't work (C is always Nothing):
Function FindTestFn() as Variant
Dim R as Range
Dim C as Range
Set R = ActiveSheet.Range("A:A")
Set C = R.Find(20,,xlValues)
FindTestFn = C.Address
End

Thanks in advance...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default range.find method called into a VBA function (problem)

Eros Pedrini wrote:
I have a problem using the find method of range object. It works fine if I
use into a Sub procedure; but fails (i.e. return nothing all time) if I use
it into a Function.


The Function works if it is called from a Sub Procedure; it doesn't if
it is called from a Worksheet. That's just the way it is in Excel.

Alan Beban
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default range.find method called into a VBA function (problem)

Dave Peterson says FIND does work in a User Defined Function (UDF) used in a
worksheet in xl2002 and later. Just for information.

--
Regards,
Tom Ogilvy

"Alan Beban" wrote in message
...
Eros Pedrini wrote:
I have a problem using the find method of range object. It works fine if

I
use into a Sub procedure; but fails (i.e. return nothing all time) if I

use
it into a Function.


The Function works if it is called from a Sub Procedure; it doesn't if
it is called from a Worksheet. That's just the way it is in Excel.

Alan Beban



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default range.find method called into a VBA function (problem)

Tom Ogilvy wrote:
Dave Peterson says FIND does work in a User Defined Function (UDF) used in a
worksheet in xl2002 and later. Just for information.

Thanks; that by itself is almost enough reason to upgrade.

Alan Beban
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default range.find method called into a VBA function (problem)

Thanks... another question... there is a workaround? Check all cells with an
each for is very expensive in time... something know another way?

Thanks again

Eros Pedrini




"Alan Beban" wrote in message
...

The Function works if it is called from a Sub Procedure; it doesn't if
it is called from a Worksheet. That's just the way it is in Excel.

Alan Beban






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default range.find method called into a VBA function (problem)

for a single column or single row, use application.Match

Function FindTestFn() As Variant
Dim R As Range
Dim res As Variant
Dim R1 As Range
Application.Volatile
Set R1 = Application.Caller
Set R = R1.Parent.Range("A:A")
res = Application.Match(20, R, 0)
If Not IsError(res) Then
FindTestFn = R(res).Address
Else
FindTextFn = CVErr(xlErrNA)
End If
End Function




--
Regards,
Tom Ogilvy

"Eros Pedrini" wrote in message
...
Thanks... another question... there is a workaround? Check all cells with

an
each for is very expensive in time... something know another way?

Thanks again

Eros Pedrini




"Alan Beban" wrote in message
...

The Function works if it is called from a Sub Procedure; it doesn't if
it is called from a Worksheet. That's just the way it is in Excel.

Alan Beban






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
Set range with Find method jlclyde Excel Discussion (Misc queries) 1 December 3rd 08 05:44 PM
Find Method problem in Excel VBA.... Irmann Excel Worksheet Functions 7 March 10th 08 03:49 AM
Problem is using any method of Range Object Shilps[_2_] Excel Programming 3 October 29th 04 06:24 AM
AppActivate problem when called twice SuperJas Excel Programming 0 March 3rd 04 06:41 AM
How do I find which cell called a function? TL[_2_] Excel Programming 3 July 12th 03 02:12 AM


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