Consulting

Results 1 to 3 of 3

Thread: Solved: Join Sheets Cells By Common Field

  1. #1

    Solved: Join Sheets Cells By Common Field

    Hi to all,

    Could somebody please help me I need to join rows from different sheets with common fields, See attachment example.
    Life is not as complicated as we think it is, we make it complicated.

    IF you can change it, then strive for excellence.
    IF not, then let it happen, don't worry about it and live a happier life.


    Let's Have Fun!
    Julio

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]
    Option Explicit
    Sub Macro1()

    Dim WS As Worksheet, wsht As Worksheet
    Dim i As Long, j As Long
    Dim c As Range

    Set WS = Sheets.Add
    Sheets("Data1").Range("A").Copy WS.Range("A1")
    For i = 2 To 3
    Set wsht = Sheets("Data" & i)
    wsht.Range("A11").Copy WS.Range("A1").Offset(, (i - 1) * 4)
    For j = 2 To WS.Cells(Rows.Count, 1).End(xlUp).Row
    Set c = wsht.Columns(1).Find(WS.Cells(j, 1))
    If Not c Is Nothing Then
    c.Resize(, 4).Copy WS.Cells(j, 1).Offset(, (i - 1) * 4)
    End If
    Next
    Next
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Thank you, it works great, of course you already knew that.
    Life is not as complicated as we think it is, we make it complicated.

    IF you can change it, then strive for excellence.
    IF not, then let it happen, don't worry about it and live a happier life.


    Let's Have Fun!
    Julio

Posting Permissions

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