I am trying to get a macro that takes 2 sheets from a Workbook and compare 2 different columns of data.
Find a number in
'Price Variances'!D2:D999999and try to match it to'Finance All'!E2:E999999If they match, then take the corresponding data from
'Finance All'!G2:G999999and paste it into the corresponding rows in'Price Variances'!U2:U999999.
Clarification
I want to look at a value in a cell in 'Price Variances', Column 'D', Row '2', then see if there is a match in 'Finance All' column 'E' (Look through entire column for a match).
If there is, I want to paste data from the corresponding row of the match from 'Finance All', Column 'G' into 'Price Variances', Column 'U', Row '2' (This is the same row of the original cell that we were searching for a match from).
This would need to process for every row there after in 'Price Variances', Column 'D'.
Below is what I have so far.
Sub Price_Variation_Finance_Match()
Dim CompareRange As Variant, x As Variant, y As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange = Range("'Finance All'!E2:E999999")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Daily Pricing (5)"). _
' Worksheets("Price Variances", "Finance All").Range("E2:E999999")
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In Selection
For Each y In CompareRange
If x = y Then x.Offset(0, 17) = x
Next y
Next x
End Sub
I believe my problem lies within the last 'x' in the If x = y Then x.Offset(0, 17) = x
Below is the Original Macro
Sub Find_Matches()
Dim CompareRange As Variant, x As Variant, y As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange = Range("C1:C5")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Book2"). _
' Worksheets("Sheet2").Range("C1:C5")
'
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In Selection
For Each y In CompareRange
If x = y Then x.Offset(0, 1) = x
Next y
Next x
End Sub