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

 
EdStockton,

New samples raw data:


Excel 2007
A
1Name
2Joe Walsh
3Tom Cary
4Bill White
5Donald Super
6Bill Downs
7Jim Burgess
8Ed White
9Cary Baker
10Jim Brown
11Carl Sayers
12Jim Foster
13
Sheet2



Excel 2007
A
1Name
2Joe Walsh
3Tom Cary
4Bill White
5Larry Smith
6Donald Super
7Jim Burgess
8Ed White
9Joe Adel
10Cary Baker
11Jim Brown
12Thomas Watkins
13Carl Sayers
14
15
16
Sheet1


After the new macro in worksheet Sheet1:


Excel 2007
A
1Name
2Joe Walsh
3Tom Cary
4Bill White
5Larry Smith
6Donald Super
7Jim Burgess
8Ed White
9Joe Adel
10Cary Baker
11Jim Brown
12Thomas Watkins
13Carl Sayers
14Bill Downs
15Jim Foster
16
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).

Code:
Sub UpdateNames_V2()
' 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("A2", .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_V2 macro.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Thank you all for your help. This has resolved my problem. I do well with formulas because I'm good with math, but programing is actually a language. I got a minor in programing as an undergraduate but that was in 1983 and I've not done any programing since. There is just so much I don't know.

I remember using a button when I got bored and did a self education course on programing with VBA about five year ago and it worked well with forms. I will try it as what I'm doing now will be a monthly procedure.

I participate in an accounting forum (being a CPA) and on that forum we are supposed to provide a response when the subject is considered resolved and provide a summary and perspective to close out the thread. Is that to be done here as well?
 
Upvote 0
EdStockton,

Thank you all for your help. This has resolved my problem.

You are very welcome. Glad we could help.

I remember using a button when I got bored and did a self education course on programing with VBA about five year ago and it worked well with forms. I will try it as what I'm doing now will be a monthly procedure.

See if something in my most up to date list, in the below link will help:

Training / Books / Sites as of 6/26/2014

http://www.mrexcel.com/forum/excel-questions/788128-compare-values-worksheets.html#post3857750


I participate in an accounting forum (being a CPA) and on that forum we are supposed to provide a response when the subject is considered resolved and provide a summary and perspective to close out the thread. Is that to be done here as well?

You do not have to do anything further - your good comments are enough.

And, come back anytime.
 
Upvote 0
I'm back again. I tried to adapt your code to a different set of circumstances and was unsuccessful.

I have uploaded the file to Box. The link is as follows: https://app.box.com/s/rljtuf4p9jwthxwnaw1m

I think I have done that correctly.

I want the code to look at the names on worksheet CD column B and compare them to the names on JanSales column J. In the names on JanSales do not appear on CD column B, I want to add those names to the end of the list on column B worksheet CD.

I tried to adapt the code you gave me but instead of the names being added to the end of column B on the CD worksheet, they are added to Column A starting at cell A2 of the CD worksheet.

I've tried, but I don't understand the code well enough to figure out why.

Eventually, I would like to put in the names of successive worksheets into a particular cell somewhere on the CD worksheet, run the code, and add the names appearing on other worksheets (FebSales, MarchSales, etc.) to column B of the CD worksheet.

Your help for someone who is new would be greatly appreciated by that person, Me.
 
Upvote 0
Hi..

Here's how i would do it..

1. Create named Ranges for each months sheet for column J.

I made one when testing called "JanSales".
Use this formula in the Refers to: field..

=OFFSET(JanSales!$J$2,0,0,MATCH("*",JanSales!$J:$J,-1)-1,1)

2. Paste the below code into a Module and run it.. it will copy the names you want over to the CD sheet in Column B and will automatically insert your SUM formulas as needed 2 rows below your last row..
So you can remove your current Sum formulas (for JanSales sheet anyway) as they will be in the wrong row when you add names..
Code:
Sub apo()
    Dim i As String, vArr, it, x, cnt As Long
    With CreateObject("scripting.dictionary")
        For Each it In Sheets("CD").Range("B6:B" & Sheets("CD").Range("B" & Rows.Count).End(xlUp).Row)
            x = .Item(it.Value)
        Next
        For Each it In Range("JanSales")
            If Not .Exists(it.Value) Then
                If i = vbNullString Then
                    i = (it): cnt = cnt + 1
                ElseIf it <> vbnulstring Then
                    i = i & "$" & (it): cnt = cnt + 1
                End If
            End If
        Next
        vArr = Split(i, "$")
        Sheets("CD").Range("B" & Sheets("CD").Range("B" & Rows.Count).End(xlUp).Row).Offset(1).Resize(UBound(vArr)).Value = Application.Transpose(vArr)


        Sheets("CD").Range("C" & Sheets("CD").Range("B" & Rows.Count).End(xlUp).Row).Offset(2).Resize(1, 14).Formula = _
        "=Subtotal(9,C6:C" & Sheets("CD").Range("B" & Rows.Count).End(xlUp).Row & ")"


        Sheets("CD").Range("D" & Sheets("CD").Range("D" & Rows.Count).End(xlUp).Row).Value = ""
    End With
End Sub

Eventually, I would like to put in the names of successive worksheets into a particular cell somewhere on the CD worksheet, run the code, and add the names appearing on other worksheets (FebSales, MarchSales, etc.) to column B of the CD worksheet.

I haven't got time right now.. but.. again.. what I would do (and there are always many ways to skin a cat).. is:

1. If you know which sheets you want to loop through and apply the same process.. then make it loop through them.. your "JanSales" range part in the code would therefore be dynamic..

2. Or.. Put all your sheet names in a cell separated by a comma or something (like you say).. or in a listbox.. etc etc.. and make the code be applied to your selection/input.

Edit: I may not have explained that too well.. let me know if you don't understand my waffling.. :)
 
Last edited:
Upvote 0
EdStockton,

Thanks for the workbook.

I have created an array to hold the worksheet names of the worksheets that you want the macro to run in.

Code:
w = Array("JanSales", "FebSales", "MarchSales", "AprilSales", "MaySales", "JuneSales")

You will have to update/change the array after you insert new monthly Sales months.


Sample worksheet CD before the macro (the YELLOW cell is the current last use cell in column B):


Excel 2007
B
1210Zena w. Green
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
CD


After the macro we have found 74 new names:


Excel 2007
B
1210Zena w. Green
1211Kathy Wheeler
1212Lamar Dorsey, III
1213Karen M. Swilley
1214Isaac Jenrette
1215E. Richard Clark
1216Marcellous Jackson
1217Linda M. Turner Lockhart
1218Demetrius Patterson
1219Samantha Nicholson
1220Dorothy Robinson
1221Lisa D. Logan
1222Medina Bolton
1223Xavier Light
1224Frederick D. Farmer
1225Annie W. Lindsey
1226Daniel Green
1227Christine A. Agnew
1228Robert Hightower
1229Carter Smith, Jr.
1230Carolyn Moon
1231Ezekiel McConnell, Sr.
1232Danny Stillwell
1233Walter Barber McClelland
1234Everett M. Ellington, Jr.
1235Sonya Bridges
1236Charleise T. Young
1237Marcus Phillips
1238Sara N. Hammond
1239Rosa Farley
1240William Carr, Jr.
1241Charles E. Wyatt
1242Judy G. Coleman
1243Gloria H. Colbert
1244Darryl M. Combs
1245Manuel Jackson
1246Carolyn Colbert
1247Abraham L. Davis
1248Beverly Carroll Daniel
1249Leroy F. Hollingsworth
1250Thales e. Walker
1251David Lamar Bertolini
1252Kenya Neal Copeland
1253Alice Spencer
1254Katrina Jones
1255Andrew William Fellers
1256Arian Johnston
1257Kathleen Johnson
1258Mearia F. Howell
1259Gail Zellars
1260Natha S. Harris
1261Phyllis Grier
1262Margie W. Clark
1263Monica Y. Spann
1264Elizabeth Markam
1265Dr. Carter Smith, Jr.
1266Ronald McCants
1267Donald L. Alford
1268RALPH A. LAMBERT
1269Kathryn Bell
1270Cynthia T. Holloway
1271Paul E. Hanley, Jr.
1272Angela Lavern Nelson
1273Irish N. Benson
1274Valerie Hudson Watts
1275Nellie Roberts
1276Shirley Brewton
1277Linda Horne Melvin
1278Susan Claire Dobbs
1279Samantha Ellington
1280Willie J. Jones
1281Betty N. Chaney
1282Shadonna Carr
1283Marion Parks
1284Mary Katherine Lenoir
1285
CD


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_V2()
' hiker95, 08/15/2014, ME797099
Dim wc As Worksheet, ws As Worksheet
Dim c As Range, b As Range
Dim w As Variant, i As Long, nr As Long, lr As Long
Application.ScreenUpdating = False
Set wc = Sheets("CD")
If wc.FilterMode Then wc.ShowAllData
w = Array("JanSales", "FebSales", "MarchSales", "AprilSales", "MaySales", "JuneSales")
For i = LBound(w) To UBound(w)
  Set ws = Sheets(w(i))
  With ws
    lr = .Cells(Rows.Count, "J").End(xlUp).Row
    For Each c In .Range("J2", .Range("J" & Rows.Count).End(xlUp))
      If c <> "" Then
        Set b = wc.Columns(2).Find(c, LookAt:=xlWhole)
        If b Is Nothing Then
          nr = wc.Cells(wc.Rows.Count, "B").End(xlUp).Row + 1
          wc.Cells(nr, "B") = c.Value
        End If
      End If
    Next c
  End With
Next i
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_V2 macro.
 
Last edited:
Upvote 0
1. Create named Ranges for each months sheet for column J.

I made one when testing called "JanSales".
Use this formula in the Refers to: field..

=OFFSET(JanSales!$J$2,0,0,MATCH("*",JanSales!$J:$J,-1)-1,1)

I am unsure what you mean by the "Refers to: field.."
 
Upvote 0
On the menu Strip.. click the Formulas Tab then the "Name Manager" option..

You will see the lower field in the popup is "Refers to:"
 
Upvote 0
apo,

I did not know what to do with the OFFSET formula so I went to cell D30 on the JanSales worksheet and typed it in and received a value error message. Apparently, I did wrong. Where should I put that formula?
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,073
Members
449,205
Latest member
Healthydogs

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