remove data from a work sheet

%3CLINGO-SUB%20id%3D%22lingo-sub-2672513%22%20slang%3D%22en-US%22%3Eremove%20data%20from%20a%20work%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2672513%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20two%20worksheets%20A%20and%20B.%26nbsp%3B%20worksheet%20B%20is%20a%20complete%20subset%20of%20worksheet%20A.%26nbsp%3B%20%26nbsp%3BI%20want%20to%20remove%20all%20the%20data%20of%20work%20sheet%20B%20from%20worksheet%20A%20forming%20a%20new%20worksheet%20C.%26nbsp%3B%20%26nbsp%3B%20Example%3A%26nbsp%3B%20I%20have%20a%20list%20of%20eligible%20voters.%26nbsp%3B%20%26nbsp%3BI%20have%20data%26nbsp%3B%20from%20the%20county%20clerk%20that%20some%20of%20the%20eligible%20voters%20have%20voted.%26nbsp%3B%20I%20want%20to%20remove%20the%20voters%20who%20have%20already%20voted%20from%20the%20the%20list%20of%20all%20vo%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2672513%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2672565%22%20slang%3D%22en-US%22%3ERe%3A%20remove%20data%20from%20a%20work%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2672565%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F55539%22%20target%3D%22_blank%22%3E%40Terry%20Armentrout%3C%2FA%3E%26nbsp%3BI'm%20inclined%20to%20suggest%20that%20you%20use%20Power%20Query%20for%20such%20a%20task.%20Connect%20to%20both%20tables%20A%20and%20B%20and%20than%20merge%20them%20with%20a%20so-called%20%22left%20anti-join%22%20that%20will%20produce%20a%20new%20table%20containing%20records%20that%20only%20exist%20in%20the%20first%20table.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20traditional%20Excel%20method%20to%20achieve%20the%20same%20would%20be%20to%20expand%20table%20A%20with%20a%20column%20that%20looks%20up%20(VLOOKUP%20or%20XLOOKUP)%20if%20the%20voter%20exists%20in%20table%20B.%20Then%20filter%20out%20the%20the%20ones%20that%20do%20and%20copy%2Fpaste%20the%20ones%20that%20don't%20to%20a%20new%20table.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2672962%22%20slang%3D%22en-US%22%3ERe%3A%20remove%20data%20from%20a%20work%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2672962%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20antijoin%20was%20made%20for%20this!%26nbsp%3B%20%26nbsp%3BI%20find%20it%20difficult%20to%20determine%20where%20the%20border%20lies%20between%20PQ%20and%20DA%3B%20the%20overlap%20in%20functionality%20is%20so%20large.%26nbsp%3B%20Perhaps%20PQ%20if%3C%2FP%3E%3CP%3E1.%20You%20are%20using%20an%20old%20copy%20of%20Excel%20(2010-2019)%3C%2FP%3E%3CP%3E2.%20The%20'voted'%20list%20is%20imported%20from%20an%20external%20source%3C%2FP%3E%3CP%3E3.%20The%20tables%20are%20large%20(perhaps%2C%20votes%20cast%20%26gt%3B%26gt%3B%2010%2C000%3F)%3C%2FP%3E%3CP%3E4.%20Dynamic%20updating%20of%20the%20'not%20voted'%20table%20isn't%20needed%3C%2FP%3E%3CP%3EDo%20you%20have%20advice%20to%20offer%20on%20the%20subject%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

I have two worksheets A and B.  worksheet B is a complete subset of worksheet A.   I want to remove all the data of work sheet B from worksheet A forming a new worksheet C.    Example:  I have a list of eligible voters.   I have data  from the county clerk that some of the eligible voters have voted.  I want to remove the voters who have already voted from the the list of all vo

5 Replies

@Terry Armentrout I'm inclined to suggest that you use Power Query for such a task. Connect to both tables A and B and than merge them with a so-called "left anti-join" that will produce a new table containing records that only exist in the first table.

 

The traditional Excel method to achieve the same would be to expand table A with a column that looks up (VLOOKUP or XLOOKUP) if the voter exists in table B. Then filter out the the ones that do and copy/paste the ones that don't to a new table.

@Terry Armentrout 

The key element of the calculation is to determine whether each person on the register has voted (once) or not.

= COUNTIFS(voted, register)

The list you require is then produced by filtering the register.

= LET(
    voted?, COUNTIFS(voted, register),
    FILTER(register, NOT(voted?))
  )

It is also possible to achieve the result in legacy spreadsheets by filtering a record index and then using SMALL to compact the list before returning the names.

@Riny_van_Eekelen 

The antijoin was made for this!   I find it difficult to determine where the border lies between PQ and DA; the overlap in functionality is so large.  Perhaps PQ if

1. You are using an old copy of Excel (2010-2019)

2. The 'voted' list is imported from an external source

3. The tables are large (perhaps, votes cast >> 10,000?)

4. Dynamic updating of the 'not voted' table isn't needed

Do you have advice to offer on the subject?

 

@Peter Bartholomew

I've only been playing around with PQ for just over a year now and have become very fond of it. It's simplicity in completing quite complicated tasks is amazing. In contrast with, for instance, VBA that often requires quite complex coding to achieve relatively simple tasks.

 

Not needing to load the data into the workbook you happen to be working in. Being able to transform the raw data without changing it. And, on top of that, PQ can handle huge amounts of data, but it works great on smaller data sets as well. Just love it.

 

I'm on the insider/beta MS365 version and have access to all the new and exciting DA functions, including LET, LAMBDA, MAP etc. and fully understand your drive to steer away from traditional Excel solutions. But, as you mentioned, many "out there" don't have access to them (yet).

 

Quite often, I see solutions with PQ sooner then with DA functions. Being quite a lazy person in that respect, I tend to opt for the easiest way out. So, to answer your question. No, I really don't have any advice. Your DA solution to the Voter problem demonstrates there is an overlap. But, I'm mostly driven by PQ's ease of use and lack of in depth knowledge of how to use all the new DA functions. I guess I'll get there at some point.

 

 

 

 

 

 

 

@Terry Armentrout 

One more mentioned but not demonstrated way

Let start from these cells

image.png

In K2

=IFERROR(INDEX(RegisteredVoters[ID],
   AGGREGATE(15,6,
      1/(COUNTIF(Voted[[ID]:[ID]],RegisteredVoters[[ID]:[ID]])=0)*
     (ROW(RegisteredVoters)-ROW(RegisteredVoters[[#Headers],[ID]])),
     ROW()-ROW($K$1))
), "")

You may drag it to the right into L2 and M2, or alternatively use

L2:
=IFERROR(INDEX(RegisteredVoters[Name], MATCH($K2,RegisteredVoters[ID],0)),"")

M2:
=IFERROR(INDEX(RegisteredVoters[DOB], MATCH($K2,RegisteredVoters[ID],0)),"")

and for the Age

=IFERROR(DATEDIF(M2, TODAY(),"y"),"")

Now you may select K2:N2 and drag it down till empty cells appear or enter into name box K2:N100 (this range will be selected) and Ctrl+D