View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Neal Zimm Neal Zimm is offline
external usenet poster
 
Posts: 345
Default Find Method within a called procedure

Ardus -
Once again, thanks.
the As Long for irow and icol, I agree with Long for the row
variables, but I guess I was not clear in my question. I suppose it does not
hurt, except for a few bytes of memory allocation, but for the COLUMN
variable, I'm pretty sure integer will do fine.

Thanks.
--
Neal Z


"Ardus Petus" wrote:

1) Sub zString_Find(...) does not "know" it's caller. All parameters should
be "dim'ed".

ByRef means that iRow & iCol parameters are transmitted "by reference" (ie:
address)
If they were declared ByVal, the called proc could not modify them

2) CVA functions Row & Column return Long.
Integer holds values up to 32767, which is not sufficient for rox # 65536

3) It's useless: once you reach the End Sub, all local variables are
destroyed

HTH
--
AP

"Neal Zimm" a écrit dans le message de
...
Hi Ardus,
Thanks, it works fine.
Couple of follow ups:
1) What is the reason for "Dim 'ing" the zString_Find vars in the sub
statement? I usually dim them in the calling macro, I'm not sure why you

use
"by ref"

2) Picking some nits,
a) any reason why you use Long for the column value?
Integer would seem to do since 256 is the max.

b) I read somewhere that when processing is done that any objects you

"set"
via Set = should have: set "name" = Nothing to free them.
I added this at the end of the zString_Find Macro.
Is there any harm in this?



--
Neal Z


"Ardus Petus" wrote:

Try this:

HTH
--
AP

'----------------------------------------
Sub a__TEST()
Dim Chars As String, lRow As Long, lCol As Long
Chars = "zzzzend"
Call zString_Find(Chars, lRow, lCol)
MsgBox "Found row,col " & lRow & ", " & lCol, , "Find this: " & Chars
End Sub


Sub zString_Find( _
IFindTheseChars As String, _
ByRef lRow As Long, _
ByRef lCol As Long)
' I var names are input, O vars are output
Set foundCell = Cells.Find( _
What:=IFindTheseChars, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If foundCell Is Nothing Then
MsgBox "String not found"
lRow = 0
lCol = 0
Else
lRow = foundCell.Row
lCol = foundCell.Column
End If
End Sub
'----------------------------------------------------------