皆様におかげさまで、本当に素朴なVBAコードで私を形にしてくださったことに感謝しています。私が進歩するにつれて、私は新しい問題に取り組んでいます。VBAを使用して検索する:=シート内の値を取得する
私の挑戦は、このコードを使用して、開いているすべてのブックで値を見つけることです。見つかった場合、残りのコードが実行されます。私は、エンドユーザーがコードに入ることなく、見つかった価値を簡単に変更できるようにしたいと考えています。そこで、Data Specs
と呼ばれるThisWorkbook
に新しいシートを追加しました。私は自分のコードが何かを見つけ出すと、セル内のこのシートの値が何であってもそれを探すはずですA2
。
Sheets("Add File Here").Select
If IsEmpty(Range("A1")) Then
Worksheets("Master Mapper").Activate
Dim answer003 As Integer
answer003 = MsgBox("Please check the Data Sheet. No value found in first row! Do you wish to find Cvent003 file in open workbooks and start process?", vbYesNo + vbQuestion, "Review & Proceed")
If answer003 = vbYes Then
'Starts here
Dim wSheet As Worksheet
Dim wBook As Workbook
Dim rFound As Range
Dim bFound As Boolean
Dim lngLastRow2 As Long
Dim Cvent003Val As Long
Cvent003Val = ThisWorkbook.Sheets("Data Specs").Cells("A2").Value
On Error Resume Next
For Each wBook In Application.Workbooks
For Each wSheet In wBook.Worksheets
Set rFound = Nothing
Set rFound = wSheet.Range("D1:D2").Find(What:=Cvent003Val, SearchFormat:=True, After:=wSheet.Range("D1"), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, MatchCase:=True)
'rFound.Cells.Select
If Not rFound Is Nothing Then
bFound = True
Application.Goto rFound, True
'Rows(1, 2).EntireRow.Hidden = True
lngLastRow2 = Cells(Cells.Rows.Count, "B").End(xlUp).Row
Range("A1:G" & lngLastRow2).Copy
ThisWorkbook.Worksheets("Add File Here").Activate
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Exit For
End If
Next wSheet
If bFound = True Then Exit For
Next wBook
If rFound Is Nothing Then
MsgBox "No open file for Cvent003 Meetings Found. Make sure the most recent Cvent003 Excel WB is open!", vbCritical + vbOKOnly
Exit Sub
End If
あなたの問題は何ですか?私はあなたの質問で質問を見ることができません。 ( "A2:")、SearchFormat:= True、After:= wSheet.Range(これは、次のように設定されています: –
'Set rFound = wSheet.Range(" D1:D2 " "D1")、_ LookIn:= xlValues、LookAt:= xlPart、SearchOrder:= xlByRows、_ SearchDirection:= xl前のMatchCase:= True) ' これは私が使用しているコードです。 Find値をセル内で調べる。今、「After」を同様の方法で変更したい!申し訳ありませんが、私は非常にはっきりしていないと思うが、私はいつものように私を助けてくれることを願っています。 @EganWolf –
ご協力いただければ幸いです!ありがとうございます –