If cell contains X (sheet 1), paste data in adjacent colums (sheet 2)

kincaidjosh

New Member
Joined
Feb 17, 2011
Messages
14
I'm have 2 sheets of data, I used VLOOKUP to compare variances from each sheet, but i need a macro or IF function to past the data next to my value.

I'd like to solve for the following:
If cell A1's value (in sheet 1) is also found in sheet 2, paste that data in adjacent columns from sheet 1 to sheet 2

Sheet 1
A B C
John Smith 34


Sheet 2
A B C
John

Requirement:
Find missing data from sheet 1's column B&C & paste to sheet 2's Row A next to the value, 'John'.

Sheet 2
A B C
John Smith 34
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
First issues I see with this, is that there is no way to tell which "John" you select. If you don't have duplicates then not an issue and you can use something like this:

Code:
Sub DoingSomeWork()

Dim lngLstRow(1 To 2) As Long
Dim wsSheet(1 To 2) As String

wsSheet(1) = "Sheet1"
wsSheet(2) = "Sheet2"

lngLstRow(1) = Sheets(wsSheet(1)).UsedRange.Rows.Count
lngLstRow(2) = Sheets(wsSheet(2)).UsedRange.Rows.Count

For Each rngCell In Sheets(wsSheet(2)).Range("A2:A" & lngLstRow(1))
    For i = lngLstRow(1) To 2 Step -1
        Sheets(wsSheet(1)).Select
            Range("A" & i).Select
             If ActiveCell.Value = rngCell.Value Then
                rngCell.Offset(0, 1).Value = ActiveCell.Offset(0, 1).Value
                rngCell.Offset(0, 2).Value = ActiveCell.Offset(0, 2).Value
            End If
    Next i
Next
             
End Sub
If you have duplicate values, you will need a way to make each row "unique" to get this to work.

Please let me know if you have any questions or run into any issues. Please be sure to back up your excel workbook before running this macro!
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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