Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Using WorksheetFunction.Find in VBA

Hi,

I have the following code snippet that I'm using to find whether one digit
is part of another large number using something like:

If IsNumeric(WorksheetFunction.Find(Third, y)) Then
Result = TRUE
Else
Result = FALSE
End If

where y is the large number and 'Third' represents the a particular digit.
If the expression in the IF statement does contain the said digit, the
result of the statement is that Result variable is assigned the value TRUE.
However, if the digit is not contained, then rather than hitting the ELSE
bit of the above statement, the code just unexpectedly terminates.

Any suggestions?

Thx,
Schiz


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Using WorksheetFunction.Find in VBA

Use Instr

Result = InStr(y, third) 0


--

HTH

Bob

"Schizoid Man" wrote in message
...
Hi,

I have the following code snippet that I'm using to find whether one digit
is part of another large number using something like:

If IsNumeric(WorksheetFunction.Find(Third, y)) Then
Result = TRUE
Else
Result = FALSE
End If

where y is the large number and 'Third' represents the a particular digit.
If the expression in the IF statement does contain the said digit, the
result of the statement is that Result variable is assigned the value
TRUE. However, if the digit is not contained, then rather than hitting the
ELSE bit of the above statement, the code just unexpectedly terminates.

Any suggestions?

Thx,
Schiz




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Using WorksheetFunction.Find in VBA

"Bob Phillips" wrote in message
...
Use Instr

Result = InStr(y, third) 0


--

HTH

Bob


Hi Bob,

That certainly does help - your solution worked like a charm, though I'm not
sure why. How is it different from what I had originally written down?

Thx.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Using WorksheetFunction.Find in VBA

It is different because the worksheet function errors out if the value is
not found, and you are not handling an error. It can be done, like so

Dim tmp As Long

On Error Resume Next
tmp = WorksheetFunction.Find(third, y)
On Error GoTo 0

Result = tmp < 0

but it is far more efficient to use a VBA function in VBA, rather than
calling out to Excel.

--

HTH

Bob

"Schizoid Man" wrote in message
...
"Bob Phillips" wrote in message
...
Use Instr

Result = InStr(y, third) 0


--

HTH

Bob


Hi Bob,

That certainly does help - your solution worked like a charm, though I'm
not sure why. How is it different from what I had originally written down?

Thx.



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
Problems with WorksheetFunction.Index and WorksheetFunction.Match Luke Excel Programming 4 October 14th 09 12:57 AM
Find WorksheetFunction - finding text within text Marcotte A Excel Programming 1 January 24th 05 10:16 PM
Problem using "Find" WorksheetFunction in Excel VBA wadeni Excel Programming 1 August 12th 04 02:49 PM
Max WorksheetFunction solo Excel Programming 4 February 23rd 04 10:17 PM
WorkSheetFunction.CountIf & WorkSheetFunction.SumIf with 2 conditions? Etien[_2_] Excel Programming 3 January 13th 04 04:07 PM


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