Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,comp.apps.spreadsheets,microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Problems with SearchInRange() macro

MS Excel 97 SR-2

Having problems with the implementation for

SearchInRange(AS13,'\Obsolescence\[obsolete-list.xls]A'!$C1:$C10,1,1)

1) Can't get the search() worksheet function to work in the macro
2) Debugger has quit on me.

Point 2 first: I have had an excel crash, tried to change the name of
a watch variable by editing it. Since restarting Excel, the VBA
debugger does not respect my breakpoints in SearchInRange(). Am
loathe to restart the PC - is there a reason for this, and more
importantly, a workaround?

Point 1: I cannot step over a line of the form

result = searchRange(1, 1).Value

This is the function prototype :

Public Function SearchInRange(searchStr, searchRange As Range,
cellPos, strPos)

VBA seems to perform a number of iterations on the "result =" line,
then when it returns the value of all watch variables are "Out of
context" (or whatever the message is, the debugger is now not
restarting).

Here is the full macro code (for the debug version, the obvious
reverse changes are performed to return it to "as-designed" :

' --------- Debug version
'
' Range equivalent to Search("M","Miriam McGovern",3) equals 8
' Search() is case insensitive, ? and * wildcard version of Find()
'
Public Function SearchInRange(searchStr, searchRange As Range,
cellPos, strPos)
SearchInRange = "SYNTAX : SearchInRange(searchStr, searchRange as
Range, cellPos, strPos)"
'
Dim result As Integer, iCell As Integer, notFound As Integer
If searchRange.Areas.Count = 1 Then
iCell = cellPos
notFound = 1
' While (iCell <= searchRange.Count & notFound)
iCell = 3
result = searchRange(1, 1).Value
result = searchRange(iCell, 1).Value
result = Application.Search(searchStr, result, strPos)
notFound = Application.IsError(result)
iCell = iCell + 1
' Wend
If (notFound) Then
SearchInRange = 0
Else
SearchInRange = iCell - 1
End If
End If
End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems with SearchInRange() macro

Find does not work within a Function (XL97)

Pehaps you could make it a sub


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming,comp.apps.spreadsheets,microsoft.public.excel.misc
external usenet poster
 
Posts: 2,824
Default Problems with SearchInRange() macro

What's in your SearchRange?

Result is dimmed as Integer. If I don't have an integer in searchrange(1,1),
then it blows up nicely.

And you may want to eschew the application.search and use VBA's Instr()
function. It looks like it'll do what you want.

There 4th parm is where you can specify the type of compare (vbtextcompare is
not case sensitive).

And the 1st parm is where you can start looking in the string.

As luck would have it, you must specify the starting position if you specify the
type of compare (Hi, Tom!).



Frederik Romanov wrote:

MS Excel 97 SR-2

Having problems with the implementation for

SearchInRange(AS13,'\Obsolescence\[obsolete-list.xls]A'!$C1:$C10,1,1)

1) Can't get the search() worksheet function to work in the macro
2) Debugger has quit on me.

Point 2 first: I have had an excel crash, tried to change the name of
a watch variable by editing it. Since restarting Excel, the VBA
debugger does not respect my breakpoints in SearchInRange(). Am
loathe to restart the PC - is there a reason for this, and more
importantly, a workaround?

Point 1: I cannot step over a line of the form

result = searchRange(1, 1).Value

This is the function prototype :

Public Function SearchInRange(searchStr, searchRange As Range,
cellPos, strPos)

VBA seems to perform a number of iterations on the "result =" line,
then when it returns the value of all watch variables are "Out of
context" (or whatever the message is, the debugger is now not
restarting).

Here is the full macro code (for the debug version, the obvious
reverse changes are performed to return it to "as-designed" :

' --------- Debug version
'
' Range equivalent to Search("M","Miriam McGovern",3) equals 8
' Search() is case insensitive, ? and * wildcard version of Find()
'
Public Function SearchInRange(searchStr, searchRange As Range,
cellPos, strPos)
SearchInRange = "SYNTAX : SearchInRange(searchStr, searchRange as
Range, cellPos, strPos)"
'
Dim result As Integer, iCell As Integer, notFound As Integer
If searchRange.Areas.Count = 1 Then
iCell = cellPos
notFound = 1
' While (iCell <= searchRange.Count & notFound)
iCell = 3
result = searchRange(1, 1).Value
result = searchRange(iCell, 1).Value
result = Application.Search(searchStr, result, strPos)
notFound = Application.IsError(result)
iCell = iCell + 1
' Wend
If (notFound) Then
SearchInRange = 0
Else
SearchInRange = iCell - 1
End If
End If
End Function


--

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
Macro problems Father John Excel Discussion (Misc queries) 3 April 20th 10 11:24 PM
Macro Problems laxnation87 Excel Discussion (Misc queries) 1 August 7th 07 05:41 PM
Macro problems Heine Excel Worksheet Functions 9 October 31st 06 11:01 AM
Macro problems Retta Excel Worksheet Functions 2 May 18th 05 10:39 PM
macro problems Peter Wiley Excel Programming 2 September 10th 03 09:53 PM


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