+ Reply to Thread
Results 1 to 6 of 6

Loop Through Column, Populate Values In Another Sheet With Matching Identifiers

Hybrid View

  1. #1
    Registered User
    Join Date
    02-13-2013
    Location
    Kansas City
    MS-Off Ver
    Excel 2010
    Posts
    3

    Loop Through Column, Populate Values In Another Sheet With Matching Identifiers

    Hi,
    I am looking to build a macro that loops through a column of identifiers with values in the adjacent column, then search a column in another sheet for the same identifier that can repeat and populate the adjacent cell with the value in the first sheet.
    See attached example.
    Thank you,

    Said another way I need

    for each item in column list
    find all identical items in another list
    populate adjacent cell
    Attached Files Attached Files
    Last edited by aeg_paul; 02-13-2013 at 02:48 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Loop Through Column, Populate Values In Another Sheet With Matching Identifiers

    Hi aeg_paul,

    Try this:

    Sub AEG(): Dim w1 As Worksheet, w2 As Worksheet, R1 As Range, R2 As Range
    Set w1 = ActiveWorkbook.Worksheets("Sheet1"): Set w2 = ActiveWorkbook.Worksheets("Sheet2")
    For Each R1 In w1.Range("A2:A" & w1.Range("A" & Rows.Count).End(xlUp).row)
    For Each R2 In w2.Range("A2:A" & w2.Range("A" & Rows.Count).End(xlUp).row)
    If R1 = R2 Then R2.Offset(, 1) = R1.Offset(, 1)
    Next: Next: End Sub
    Directions for running the routine(s) just supplied

    Copy the code to the clipboard

    Press ALT + F11 to open the Visual Basic Editor.

    Open a macro-enabled Workbook or save your Workbook As Macro-Enabled

    Select “Module” from the Insert menu

    Type "Option Explicit" then paste the code under it

    With the cursor between Sub and End Sub press F5 (F8 to Single Step)

    OR

    Press ALT + Q to close the code window.

    Press ALT + F8 then double click on the macro name
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    02-13-2013
    Location
    Kansas City
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Loop Through Column, Populate Values In Another Sheet With Matching Identifiers

    Thanks xladept,
    So I have a better understanding of the code, the argument "A2:A" in the range function, what is that indicating?
    Thank you,

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Loop Through Column, Populate Values In Another Sheet With Matching Identifiers

    w1.Range("A2:A" & w1.Range("A" & Rows.Count).End(xlUp).row)
    is like writing Range("A2:A10") but the last row is flexible - the code is used this way when you don't know the last row for sure

  5. #5
    Registered User
    Join Date
    02-13-2013
    Location
    Kansas City
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Loop Through Column, Populate Values In Another Sheet With Matching Identifiers

    Thanks for your help. Code works perfectly

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Loop Through Column, Populate Values In Another Sheet With Matching Identifiers

    You're welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1