View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Neal Zimm Neal Zimm is offline
external usenet poster
 
Posts: 345
Default Object syntax, multiple worksheets

Hi again,
The proc below works, but not quite in the way I had anticipated.
The object in line B below did not work when searching more than
1 worksheet and I don't know enough yet to understand why.
My work around was to use lines D and E.
Can you explain the problem?
Thanks again,
Neal Z.

Sub zString_FindGeneral(ByRef IFindThis As String, _
ByRef IAllRtesOrOne As String, _
ByRef IFmRow As Long, ByRef IFmCol As Integer, ByRef IToRow As Long, ByRef
IToCol As Integer, _
ByRef OErrMsg As String, _
ByRef OFoundQty As Integer, ByRef OFoundAry As Variant)

' Fill the OFoundAry array with the results of a string search;
' Calling macro determines if one sheet or more will be searched.
' Array column 1= worksheet name, 2= row number, 3= column number
' OFoundQty is the number of cells found containing the IFindThis string.

Dim RteQty As Integer, Route As String
Dim RteIx As Integer ' index
Dim RteNameAry(1 To 26) As String
Dim RteCells As Object, FirstAddress As String, FoundCell As Object
Const AryRteCol = 1 ' Columns in the OFoundAry
Const AryRowCol = 2
Const AryColCol = 3

OFoundQty = 0
OErrMsg = ""

Application.ScreenUpdating = False
If LCase(IAllRtesOrOne) = "all" Then 'makes an array of selected worksheet
names
Call zRte_NameAry_Make(Yes, No, "", RteQty, RteNameAry, OErrMsg)
If OErrMsg < "" Then Exit Sub
Else
RteQty = 1
RteNameAry(1) = ActiveSheet.name
End If

For RteIx = 1 To RteQty

'LINES A, B, C WORK WHEN SEARCHING ONE WORKSHEET (RteQty=1), D
E were commented out.
'line B errors out with application or object defined error when RteQty
is 1, i.e. more than 1 sheet
Route = RteNameAry(RteIx)
'LINE A
'Set RteCells = Worksheets(Route).Range(Cells(IFmRow, IFmCol),
Cells(IToRow, IToCol)) 'LINE B
'With RteCells
'LINE C

'Lines A, D, E work when searching one or multiple worksheets.
B C were commented out.
Worksheets(Route).Activate
'LINE D
With Range(Cells(IFmRow, IFmCol), Cells(IToRow, IToCol))
'LINE E

Set FoundCell = .Find(IFindThis, LookIn:=xlFormulas)
If Not FoundCell Is Nothing Then
FirstAddress = FoundCell.Address
OFoundQty = OFoundQty + 1
OFoundAry(OFoundQty, AryRteCol) = Route
OFoundAry(OFoundQty, AryRowCol) = FoundCell.Row
OFoundAry(OFoundQty, AryColCol) = FoundCell.Column
Do
Set FoundCell = .FindNext(FoundCell)
If Not FoundCell Is Nothing And FoundCell.Address <
FirstAddress Then
If OFoundQty < UBound(OFoundAry, 1) Then
OFoundQty = OFoundQty + 1
OFoundAry(OFoundQty, AryRteCol) = Route
OFoundAry(OFoundQty, AryRowCol) = FoundCell.Row
OFoundAry(OFoundQty, AryColCol) = FoundCell.Column
Else
MsgBox "Program limit of " & UBound(OFoundAry, 1) & "
found cells has been reached."
Exit Do ' todo, expand above error message pgm limit
reached
End If
End If
Loop Until Not FoundCell Is Nothing And FoundCell.Address =
FirstAddress
Else ' IFindThis string is not found the first time
End If
End With
If OFoundQty = UBound(OFoundAry, 1) Then Exit For
Next RteIx
End Sub

--
Neal Z