Macro for Match/ Index then Copy Paste

MJA001

New Member
Joined
Dec 28, 2017
Messages
28
Hello,

I'm new to the forum and to Macro writing.

I'm looking for a macro to help me copy and paste city names from column A in sheet2 into sheet1 column C if the names from sheet2 column C match the name in sheet1 cell B1.

Then move on through all the rows of column C in sheet2 until it hits an empty cell and can stop.


Can someone help me out? From my limited understanding I believe this has something to do with Index Match but I'm having trouble figuring out where to start.

Thanks in advance.

If this topic has already been addressed, please point me to thread.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi MJA001,

Welcome to MrExcel!!

See how this goes:

Code:
Option Explicit
Option Compare Text 'Make case matching insensitive
Sub Macro1()

    Dim rngMyCell As Range
    
    Application.ScreenUpdating = False

    For Each rngMyCell In Sheets("Sheet2").Range("C2", Sheets("Sheet2").Range("C" & Rows.Count).End(xlUp)) 'Works from cell C2 down column C in Sheet2. Change to suit if necessary.
        If rngMyCell = Sheets("Sheet1").Range("B1") Then
            Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Offset(1, 0).Value = rngMyCell.Offset(0, -2)
        End If
    Next rngMyCell
    
    Application.ScreenUpdating = True
    
End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,215,005
Messages
6,122,661
Members
449,091
Latest member
peppernaut

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