Searching Multiple sheets

jhaynes

New Member
Joined
Mar 25, 2009
Messages
5
Hello,
This is what I am trying to do:

IF ((the value at Sheet3!G2 is found in Sheet2!G) AND (the value in
Sheet2!H? is not empty )
THEN
copy the value of Sheet2!H? to Sheet3!H2
ELSE IF ((the value at Sheet3!G2 is found in Sheet1!A) AND (the value
in Sheet1!F? is not empty )
THEN
copy the value of Sheet1!F? to Sheet3!H2

Many thanks,
Justin
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Could you clarify what the F?, H? denote. I am assuming the '?' corresponds to the row the in which the value is found in Sheet2!G and Sheet1!G.
 
Upvote 0
If my assumption about the '?' is correct the following code should work.
Code:
Sub multipleSheetSearchAndCopy()
    Dim searchVal As String
    Dim result1 As Range, result2 As Range, destRng As Range
    
    searchVal = Worksheets("Sheet3").Range("G2").Value
    Set destRng = Worksheets("Sheet3").Range("H2")
    
    '// Search Sheet 1 using Find Method 
    Set result1 = Worksheets("Sheet1").Range("A:A").Find(What:=searchVal, _
                            LookIn:=xlValues, LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                            MatchCase:=True, SearchFormat:=False)
        
    '// Search Sheet 2 using Find Method
    Set result2 = Worksheets("Sheet2").Range("G:G").Find(What:=searchVal, _
                            LookIn:=xlValues, LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                            MatchCase:=True, SearchFormat:=False)
    
    If Not result2 Is Nothing Then
        If result2.Offset(0, 1).Value <> "" Then
            destRng.Value = result2.Offset(0, 1).Value
        End If
    ElseIf Not result1 Is Nothing Then
        If result1.Offset(0, 5).Value <> "" Then
            destRng.Value = result1.Offset(0, 5).Value
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top