Append Unique Data

EdStockton

New Member
Joined
Aug 6, 2014
Messages
47
I have a question that I am sure is not unique. I have one Workbook with a column of data in Sheet1 and a column of data in Sheet2.

The column on Sheet1 is my master customer list. Most customers are repeat customers but each month we get a few new customers. I show the current month sales on Sheet2. I want to compare the list on Sheet1 with the list on Sheet2. If there are names on Sheet2 that do not appear on Sheet1, I want to add those customer names to the bottom of the list on Sheet1.

Any help would be appreciated.

Thanks, Ed Stockton

 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
EdStockton,

Welcome to the MrExcel forum.

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


So that we can get it right the first time:

Can you post screenshots of the two actual raw data worksheets?

And, can you post a screenshot of the worksheet results (manually formatted by you) that you are looking for?


To post your data, you can download and install one of the following two programs:
1. MrExcel HTMLMaker20101230
https://onedrive.live.com/?cid=8cffdec0ce27e813&sc=documents&id=8CFFDEC0CE27E813!189

Installation instructions here:
http://www.mrexcel.com/forum/board-announcements/515787-forum-posting-guidelines.html#post2545970

2. Excel Jeanie
Download


If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Last edited:
Upvote 0
If Names are in column A of both the sheets And Start From A2 cell
Code:
Sub CopyNewNames()
Dim Sh1 As Worksheet, Sh2 As Worksheet
Dim LR1 As Long, LR2 As Long, TR As Long, X As Long


Set Sh1 = Sheets("Sheet1")
Set Sh2 = Sheets("Sheet2")


LR1 = Sh1.Range("A" & Rows.Count).End(xlUp).Row
LR2 = Sh2.Range("A" & Rows.Count).End(xlUp).Row


X = 1
With Sh2
For TR = 2 To LR2
    
    If WorksheetFunction.CountIf(Sh1.Range("A2:A" & LR1), .Range("A" & TR)) = 0 Then
    Sh1.Range("A" & LR1 + X) = .Range("A" & TR)
    X = X + 1
    End If
    
Next TR
End With


End Sub
 
Upvote 0
EdStockton,

Sample worksheets before the macro:


Excel 2007
A
1Names
2Name A
3Name B
4Name C
5Name D
6Name E
7Name F
8Name G
9Name H
10Name I
11
Sheet2



Excel 2007
A
1Names
2Name A
3Name B
4Name C
5Name D
6
7
8
9
10
11
Sheet1


After the macro in worksheet Sheet1:


Excel 2007
A
1Names
2Name A
3Name B
4Name C
5Name D
6Name E
7Name F
8Name G
9Name H
10Name I
11
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub UpdateNames()
' hiker95, 08/07/2014, ME797099
Dim w1 As Worksheet, w2 As Worksheet
Dim c As Range, a As Range, nr As Long
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w2
  For Each c In .Range("A1", .Range("A" & Rows.Count).End(xlUp))
    Set a = w1.Columns(1).Find(c, LookAt:=xlWhole)
    If a Is Nothing Then
      nr = w1.Cells(w1.Rows.Count, "A").End(xlUp).Row + 1
      w1.Cells(nr, 1) = c
    End If
    Set a = Nothing
  Next c
End With
With w1
  .Columns(1).AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the UpdateNames macro.
 
Upvote 0
Using the same sheet layouts as hiker95 did.. here is another..

Code:
Private Sub CommandButton1_Click()
    Dim i As String, vArr, it, x, cnt As Long
    With CreateObject("scripting.dictionary")
        For Each it In Sheets("Sheet1").Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
            x = .Item(it.Value)
        Next
        For Each it In Sheets("Sheet2").Range("A2:A" & Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row)
            If Not .Exists(it.Value) Then
                If i = vbNullString Then
                    i = (it): cnt = cnt + 1
                Else
                    i = i & "|" & (it): cnt = cnt + 1
                End If
            End If
        Next
        vArr = Split(i, "|")
        Sheets("Sheet1").Range("A" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row).Offset(1).Resize(cnt).Value = Application.Transpose(vArr)
    End With
End Sub
 
Upvote 0
I'm probably making a mess of this but I will try.

I'm using Excel 2013.

I did intend to upload my Excel Workbook but was told that uploads were not permitted. Now that you have told me of this MrExcel upload tool I will attempt to use that to show the data.

Sheet1 is as follows:

Name

Joe Walsh
Tom Cary
Bill White
Larry Smith
Donald Super
Jim Burgess
Ed White
Joe Adel
Cary Baker
Jim Brown
Thomas Watkins
Carl Sayers
<colgroup><col width="105" style="width: 79pt; mso-width-source: userset; mso-width-alt: 3726;"> <tbody> </tbody>


Sheet2 is as follows:

Name
Joe Walsh
Tom Cary
Bill White
Donald Super
Bill Downs
Jim Burgess
Ed White
Cary Baker
Jim Brown
Carl Sayers
Jim Foster
<colgroup><col width="85" style="width: 64pt; mso-width-source: userset; mso-width-alt: 3015;"> <tbody> </tbody>

The only names that appear on Sheet2 that do not appear on Sheet1 that should be appended to Sheet1 are Bill Downs and Jim Foster.

I see that many have replied. I'm fumbling with this web site but I sincerely thank you for this forum.

I will review the replies.

Thank you, Ed Stockton
 
Upvote 0
I tried the sub provided by kvsrinivasamurty and hiker95 and they both worked great. I tried the solution provided by apo and Excel didn't seem to think I had a macro installed. I noticed it began differently with "Private Sub CommandButton1_Click()" I probably just don't know how to activate such a function. Help on using that would be appreciated.

Thank you for your replies, Ed Stockton
 
Upvote 0
EdStockton,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.


I tried the solution provided by apo and Excel didn't seem to think I had a macro installed.

apo's reply macro uses the Scripting.Dictionary.

Here is what you will have to do to use his their macro:

See the following two links to add a command button:

How To: Assign a Macro to a Button or Shape - Peltier Tech Blog

How to insert Buttons, radio buttons and check boxes in Excel - Bing Videos


You may have to add the Microsoft Scripting Runtime to the References - VBA Project.

With your workbook that contains apo's macro code:

Press the keys ALT + F11 to open the Visual Basic Editor

In the VBA Editor, click on:
Tools
References...

Put a checkmark in the box marked
Microsoft Scripting Runtime

Then click on the OK button.

And, exit out of the VBA Editor.

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm
 
Upvote 0
EdStockton,

I did intend to upload my Excel Workbook but was told that uploads were not permitted.

You can upload your workbook to Box Net,

sensitive data changed

mark the workbook for sharing

and provide us with a link to your workbook.
 
Upvote 0
Hi..
I noticed it began differently with "Private Sub CommandButton1_Click()" I probably just don't know how to activate such a function.

To add a CommandBUtton:

1. Go to Developer Tab (enable this Tab if it is not already).

2. Goto Insert > Active X Controls > Command Button.

3. Left click on your sheet somewhere to place the button and then double click on that button.

4. Add the code I made (not including the "Private Sub CommandButton1_Click()" and the "End Sub") as it will already be there.. so just copy and paste everything else and add it in between these two lines that will already exist.

5. The code will now run when you click the button.

Note: The "Design Mode" button turns Design mode on and off.. if Design mode is on.. clicking your button will not run it.. double clicking it will take you to the code beneath it..

So to run the code.. make sure you are NOT in Design Mode.

Edit: oops.. I didn't see hiker95's post #8.. that is a better explanation.. thanks mate..
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

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