文字列を含む選択したセルの一覧をループし、各文字列を取り込み、その文字列のブック全体を検索するマクロを作成する必要があります。文字列が見つかった場合、サブは終了し、見つかった文字列を選択する必要があります。そうでなければ、リストの終わりまで見つかる次の文字列に移動します。Excel VBA - セルの列をループし、ブック内の各セルの値を検索します
私のコードを実行すると、リスト内の文字列が見つかってもそのセルに移動しないと、サブは終了しません。
Option Explicit
Dim sheetCount As Integer
Dim datatoFind
Sub Button1_Click()
Find_File
End Sub
Private Sub Find_File()
Dim c As Range
Dim counter As Integer
Dim currentSheet As Integer
Dim notFound As Boolean
notFound = True
For Each c In Selection.Cells
On Error Resume Next
currentSheet = ActiveSheet.Index
datatoFind = StrConv(c.Value, vbLowerCase)
If datatoFind = "" Then Exit Sub
sheetCount = ActiveWorkbook.Sheets.Count
If IsError(CDbl(datatoFind)) = False Then datatoFind = CDbl(datatoFind)
For counter = 1 To sheetCount
Sheets(counter).Activate
Cells.Find(What:=datatoFind, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
If InStr(1, StrConv(ActiveCell.Value, vbLowerCase), datatoFind) Then
notFound = False
Sheets(counter).Activate
Range("datatoFind").Select
Exit For
End If
Next counter
If notFound = True Then
MsgBox ("Value not found")
Sheets(counter).Activate
Else
Exit Sub
End If
Next c
End Sub
ご協力いただきありがとうございます。
ありがとう男...それは理解するのに役立つ願っていますあなたのコード
劇的な変化はありません!あなたは私のリストがあった同じシートを検索する問題を解決し、発見されたセルにもっときれいにやって来る方法を見つけました。 – Ozone11