Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Search worksheet from add-in

I am trying to search for specific text in a worksheet. I need to do this
from a udf that is in an add-in, and the search does not return a value (rng
= Nothing). If I copy the logic to a module in the workbook itself, it
works.

dim rng as Range
dim Wb as Workbook

Wb = ActiveWorkbook

Set rng = Wb.Worksheets("Sheet1").Columns(1).Find("mystring" )

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Search worksheet from add-in

Hi,
I suppose you are using the function in a worksheet eg: =MyFucntion(...)

VBA for Excel is quite strict when developing Worksheet UDFs. Not only you
cannot use methods that change things eg: change a format, sheet name..., but
also, some other methods/properties cannot be used Eg: Range.Find ,
Range.SpecialCells, Range.CurrentRegion, Range.CurrentArray....

If you use one of the above, the function may become unstable and the
execution of the function may exit before reaching the End Function (test
with debug.Print here and there).

--
Regards,
Sébastien
<http://www.ondemandanalysis.com
<http://www.ready-reports.com


"BigJimmer" wrote:

I am trying to search for specific text in a worksheet. I need to do this
from a udf that is in an add-in, and the search does not return a value (rng
= Nothing). If I copy the logic to a module in the workbook itself, it
works.

dim rng as Range
dim Wb as Workbook

Wb = ActiveWorkbook

Set rng = Wb.Worksheets("Sheet1").Columns(1).Find("mystring" )

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Search worksheet from add-in

You can use .Find() in UDFs in xl2002+.

Before that, you have to use a different technique. Application.match() is one
that may work for you.

Dim Res as variant
dim myRng as range
set myrng = Wb.Worksheets("Sheet1").Columns(1)
res = application.match("mystring",myrng,0)

if iserror(res) then
'not found
else
msgbox myrng(res)
end if



BigJimmer wrote:

I am trying to search for specific text in a worksheet. I need to do this
from a udf that is in an add-in, and the search does not return a value (rng
= Nothing). If I copy the logic to a module in the workbook itself, it
works.

dim rng as Range
dim Wb as Workbook

Wb = ActiveWorkbook

Set rng = Wb.Worksheets("Sheet1").Columns(1).Find("mystring" )

Thanks!


--

Dave Peterson
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
Search one worksheet to pull data into another worksheet HyperMite Excel Worksheet Functions 6 March 4th 09 01:53 PM
Search one worksheet for values in another worksheet? ClayShooters Excel Discussion (Misc queries) 1 July 4th 06 03:01 PM
Search for worksheet name Phil Excel Programming 3 May 26th 06 06:18 PM
Search for worksheet jarvis1979 Excel Programming 2 July 6th 05 05:31 PM
Create a search Field within a worksheet to search command buttons Ed P[_2_] Excel Programming 1 December 14th 04 08:04 PM


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