match strings and copy it to adjacent cell

lady_alina

Board Regular
Joined
Feb 18, 2015
Messages
52
Hi,

Here I'm again with another problem... please help me experts..

I have data in column B sheet 1 which is something like this - 123alina09032015 &
I have data in column A sheet 2 which is like this - alina.

The data is huge and keeps adding every month. So what I want is a VBA code to match the words from column A sheet 2 and column b sheet1 and paste it to the adjacent cell in column c of sheet 1

I have a code but that only finds the exact match and pastes it to column c in sheet 1. Here is the code:


Code:
Sub CopyBasedonSheet1()

Dim i As Long
Dim j As Long
Sheet1LastRow = Worksheets("sheet1").Range("B" & Rows.Count).End(xlUp).Row
Sheet2LastRow = Worksheets("sheet2").Range("A" & Rows.Count).End(xlUp).Row


    For j = 1 To Sheet1LastRow
        For i = 1 To Sheet2LastRow
            If Worksheets("sheet1").Cells(j, 1).Value = Worksheets("sheet2").Cells(i, 4).Value Then
                Worksheets("sheet1").Cells(j, 3).Value = Worksheets("sheet2").Cells(i, 1).Value
            Else
        End If
    Next i
Next j
End Sub

Looking forward to your answer.
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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