Return a value if data matches

reseng

New Member
Joined
Jun 24, 2024
Messages
15
Office Version
  1. 365
Platform
  1. Windows
I have two separate spreadsheets with vehicle registrations and dates. The two spreadsheets correspond to two different locations. The dates correspondence to when a vehicle made a trip to that location.



I want to find out when a particular vehicle made a trip to both locations on same date and return vehicle reg. Like matching dates for a particular vehicle for two locations. Really appreciate your help in advance.
 
Is it possible to keep it like before in terms of column where reg is displayed. Like a designated column instead of +1
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
It works perfectly but I am trying not to mess up the spreadsheet as it belongs to someone else. :) Thanks for putting up with me.
 
Upvote 0
Replace this line of code:
VBA Code:
.Cells(dic(val), hd1.Column + 1) = v2(i, 1)
with this line:
VBA Code:
.Range("Y" & dic(val)) = v2(i, 1)
 
Upvote 0
I have a column with heading "tonnage" in sheet2, when the two dates match and matching date is displayed I want to be able to display the corresponding tonnage in Sheet 1 as well. Please help!
 
Upvote 0
In which column in Sheet2 is the heading "Tonnage"? Will this column always be the same? In which column in Sheet1 do you want to display the tonnage?
 
Upvote 0
The tonnage is in column "O" in sheet 2. And I want to display it next to column where I displayed the matching dates in sheet 1. Thanks
 
Upvote 0
Try:
VBA Code:
Sub CompareData()
    Application.ScreenUpdating = False
    Dim WS1 As Worksheet, WS2 As Worksheet, v1 As Variant, v2 As Variant, dic As Object, val As String, hd1 As Range, hd2 As Range
    Set WS1 = ThisWorkbook.Sheets("Sheet1")
    Set WS2 = ThisWorkbook.Sheets("Sheet2")
    Set hd1 = WS1.Rows(1).Find("Date Gross Weighed", LookIn:=xlValues, lookat:=xlWhole)
    Set hd2 = WS2.Rows(1).Find("GD", LookIn:=xlValues, lookat:=xlWhole)
    v1 = WS1.Range("A2", WS1.Range("A" & Rows.Count).End(xlUp)).Resize(, hd1.Column).Value
    v2 = WS2.Range("A2", WS2.Range("A" & Rows.Count).End(xlUp)).Resize(, hd2.Column).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v1) To UBound(v1)
        val = v1(i, 1) & "|" & v1(i, hd1.Column)
        If Not dic.exists(val) Then
            dic.Add val, i + 1
        End If
    Next i
    For i = LBound(v2) To UBound(v2)
        val = v2(i, 1) & "|" & v2(i, hd2.Column)
        If dic.exists(val) Then
            With WS1
                .Range("Y" & dic(val)) = v2(i, 1)
                .Range("Z" & dic(val)) = WS2.Range("O" & i + 1)
            End With
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,221,813
Messages
6,162,117
Members
451,743
Latest member
matt3388

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