How to add new items from list A to list B
Results 1 to 2 of 2

Thread: How to add new items from list A to list B
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Aug 2013
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default How to add new items from list A to list B

    Hi.

    I have a sheet where I am working out product sales.

    In Sheet1 Column A I have all my SKUs.

    Each week when I product a report I want to store the current sales into Sheet2 so I can look back over time.

    The problem is, as we add new products, the list of SKUs in Sheet1 will grow.

    So I need to run through the SKUs on Sheet1 and if I found a matching SKU on Sheet2 then I will simply add the sales for that SKU.
    If I do not find that SKU on Sheet2 then I need to add that SKU to the end of the list.

    In short I need to compare two lists, then anything in list A that is not in list B, add it to list B, the rest of the copying data I can manage.
    I cannot rearrange list B though since it has sales data in other columns. I can only ADD to list B.

    I need to do this with a macro as I need to pass off this sheet to a colleague who does not understand Excel too much.

    Thanks

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,261
    Post Thanks / Like
    Mentioned
    49 Post(s)
    Tagged
    14 Thread(s)

    Default Re: How to add new items from list A to list B

    Let's start with this.
    Read the sku in sheet1, in column A, and look for them in sheet2 in the column. If you can not find it, add the sku to the end of column A on sheet2.


    Code:
    Sub add_new_items()
        Dim sh1 As Worksheet, sh2 As Worksheet, c As Range, f As Range
        
        Set sh1 = Sheets("Sheet1")
        Set sh2 = Sheets("Sheet2")
        For Each c In sh1.Range("A2", sh1.Range("A" & Rows.Count).End(xlUp))
            Set f = sh2.Range("A:A").Find(c, LookIn:=xlValues, lookat:=xlWhole)
            If f Is Nothing Then
                sh2.Range("A" & Rows.Count).End(xlUp)(2) = c.Value
            End If
        Next
    End Sub
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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