| 
    
     |  | はじめまして。 
 excel2000を使用しているのですが、
 検索処理が貧弱なため(全シート検索ができない)
 検索マクロを組みました。
 のですが、とある場合にエラーが発生してしまいます。
 
 とある場合というのは
 同一シート内に検索文字ヒットセルが1つのみ、かつ
 そのセルが結合セルであるときに発生します。
 FindNextメソッドが値を返してくれないために
 エラーになっているようなのですが、対処方法がわかりません。
 
 お恥ずかしい限りですが、もしよろしければ対処方法を
 ご教授の程よろしくお願いいたします。
 以下、コードです。(検索結果をリストに吐き出している処理です。)
 
 Sub MakeList()
 Dim i As Integer
 Dim myCell As Range
 Dim myFirstCell As Range
 Dim myCellAdress As String
 Dim myFirstCellAdress As String
 
 
 For i = Me.ListBox1.ListCount - 1 To 0 Step -1
 Me.ListBox1.RemoveItem (i)
 Next i
 For i = 1 To Worksheets.count
 If LookAtCheckBox.Value = True Then
 Set myCell = Worksheets(i).Cells.Find(what:=Me.SearchTextBox.Text, _
 after:=Range("A1"), _
 LookAt:=xlWhole, _
 MatchCase:=MatchCaseCheckBox.Value, _
 MatchByte:=Me.MatchByteCheckBox.Value)
 Else
 Set myCell = Worksheets(i).Cells.Find(what:=Me.SearchTextBox.Text, _
 after:=Range("A1"), _
 LookAt:=xlPart, _
 MatchCase:=MatchCaseCheckBox.Value, _
 MatchByte:=Me.MatchByteCheckBox.Value)
 End If
 
 If Not myCell Is Nothing Then
 Me.MultiPage1(1).ListBox1.AddItem (Worksheets(i).Name & "/" & myCell.Address)
 Set myFirstCell = myCell
 myFirstCellAdress = myFirstCell.Address
 Do
 
 Set myCell = Worksheets(i).Cells.FindNext(after:=myCell)
 myCellAdress = myCell.Address
 '        If myCell.Address = myFirstCell.Address Then
 If myCellAdress = myFirstCellAdress Then
 Exit Do
 End If
 
 Me.MultiPage1(1).ListBox1.AddItem (Worksheets(i).Name & "/" & myCell.Address)
 
 DoEvents
 Loop
 End If
 Next i
 
 Set myFirstCell = Nothing
 Set myCell = Nothing
 End Sub
 
 |  |