Removing opposites from Excel - excel

I am trying to figure out a way to remove values that have a net result of zero. For example I have data that is 10,000 and -10,000. They are linked to the same person though not the only transaction linked to a single individual.
Is there a method to remove both of these rows from my Excel document?
Here is a the kind of data I'm looking at
And I want to remove all but the last row as it is the only unique one.

If you create a helper column with =ABS(A1) copied down and then sort on ColumnB, that helper column and within that on ColumnA - you should end up with sets as you already have pairs. Then in another helper column Row2 and copied down:
=IF(OR(A1=-A2,A2=-A3),"#","")
should flag 'equal and opposites' next to one another. Remove those and repeat until no more flags appear, if you have multiple instances of equal and opposite values. Beware however where the last value for one Cust # is equal and opposite to the first value of the next Cust #.

Related

Test for the presence of a value and, if so, if other cells in that row fall within range

I'm attempting to check one list of roadways (each has a unique identifier) against a separate list in Excel. If that roadway on the first list is present on the second I then want to see if it also falls within the milepoints on the second list (for both lists I have a column with for the beginning milepoint and a column for the ending milepoint).
The formula (located in cell CC3) I have that is checking for the roadway on the second list is this:
=IF(ISNA(VLOOKUP('Sheet1'!CA3,'Sheet2'!Y:Y,1,FALSE)),"",VLOOKUP('Sheet1'!CA3,'Sheet2'!Y:Y,1,FALSE))
I'm attempting to write a formula in another column that will check to see if the milepoints from the first sheet fall within the milepoints on the second sheet. Here is the formula for that:
=IF(AND(CC3<>"",F3>='Sheet2'!F2,G3<='Sheet2'!G2),"YES","")
Column F is the beginning milepoint and Column G is the ending milepoint on both sheets.
I realized that this formula isn't doing what I want since the second and third logic tests are simply looking at those respective cells on Sheet 2, not at the Column F & G values on the same row where it found the matching roadway unique identifier. How would I go about fixing this? I can seem to reason my way through it. Thanks for any help you can provide!

Complex Lookup Function in Excel using 4 different lookup parameters

I am working on a project within an excel database and am trying to match 4 different properties which all have their own columns (A,B,C,D) to find a corresponding value on a different page (Sheet2!). One sheet 2 the values are once again found in their own columns (B,C,D,E) and if all of the values match I then want the value in column A Sheet2! to be displayed in column E on sheet1!
The problem is is that often times the values on Sheet1! will be able to match up with as many as 12 different unique rows on Sheet2! making this incredibly difficult with only intermediate experience in VBA. There can be duplicates that match all of the criteria. And for when this happens I would like to return the first item that matches, as long as a previous match was not made on that item.
To give you more information we have given products different values that designate where they belong based off their velocity. This has split them up into Section#, ShelvingType, Verticle, and Horizontal Location. And we are looking to match these values to the values of our previously existing locations that we have that have corresponding(matching) numbers or text values.
To go into even more detail, on sheet one we have the products with values on where they should go. One sheet two with have pre-existing locations for which products can go that have values that are represntative of that location. So, we want to take the products NEW location values off page one and match the existing location values on page two. The problem is that for every location there are up to 12products that could go there. So, we want to go in order saying that product1 goes in the first location with matched values while product2 goes in the next location with matched values, and so on and so fourth
Edited to remove previous responses
Based on your further elaboration, if I understand correctly, I agree with the comment left by #Aaron Contreras. You should create helper columns which show a 'unique ID' where all criteria match, as well as an additional helper column which increases as more items of the same criteria code are found. This will become the 'ultra-unique' ID for that item.
At this point I don't think array formulas will be possible, though I will leave in the answer which provides the result of the first matching criteria without further eliminating 'previously used' results. This could likely be further refined, but I doubt it would be more elegant than simply using the helper columns shown in my response below. At least, I can't figure out how to do it elegantly.
To summarize my assumptions:
-Your available space is in sheet1; column A contaions something like the location of that available space, and columns B-E contain criteria for anything which will be stored there.
-Your new list of items to be placed in a location is in sheet2; columnA will be where our formula goes, showing the available location to put that item.
Enter on Sheet1
In column F on sheet1, drag down this formula:
=B1&C1&D1&E1
This will create a unique ID key to be searched in the future.
However, as there will be multiple hits for the same criteria on sheet1 (because multiple locations can hold the same thing), we need to make each row 'more unique' by showing how many times that criteria combination has already occurred. This formula will thus go in column G on sheet1, starting in cell G1 and dragged down:
=F1&countif($F$1:F1,F1)
As you drag it down, this will count the nth time that the specific combination of criteria has appeared on sheet1.
Enter on Sheet2
Create the same columns in sheet2, in columns F & G. The formulas will be exactly the same, they will just refer to sheet2 instead of sheet1.
Then the formula in column A in sheet 2, dragged down from A1, would be:
=index(sheet1!A:A,match(G1,sheet1!G:G,0))
This will find the first time that all criteria match from sheet1, for the nth time that this criteria has been used on sheet 2.
Let me know if there is anything here I've missed.
Unfinished array method
Again, array responses are possible, but for your purposes likely unnecesarry; you should probably have a unique ID for all combinations anyway. However, in case you want to use the array method, you can like so (does not account for multiple locations being used; left for reference only if you want to take this up):
In sheet2, enter the following formula [confirmed with CTRL + SHIFT + ENTER instead of just ENTER, every time the formula is changed] on the row 1, with the different criteria (and copied down):
=index(Sheet1!A1:A100,match(1,(Sheet1!B1:B100=B1)(Sheet1!C1:C100=C1)(Sheet1!D1:D100=D1)*(Sheet1!E1:E100=E1),0))
This uses the inherent boolean logic of "TRUExTRUE = TRUE; TRUExFALSE = FALSE; FALSExFALSE = FALSE", to find the first row where there is a match of all criteria. Note that I have not made this go all the way down all columns, as with Array formulas this is a significant resource hog.
Assuming that your data starts from 2nd row (1st row for lables):
{MATCH(A1&B1&C1&D1,B2:B100&C2:C100&D2:D100&E2:E100,0)}
The above is an array formula, so you don't have to input the curly brackets {.
Simply press Ctrl + Shift + Enter after typing the formula
More info

Excel Instance Parsing

I have a list of data "instances" within one column within an excel sheet.
Each instance can have numerous copies. Here is an example:
abcsingleinstanceblah0001
cdemultipleinstanceexample0001
cdemultipleinstanceexample0002
cdemultipleinstanceexample0003
cdemultipleinstanceexample0004
....
Unfortunately the numbering scheme was not preserved across all of this data. So in some cases copies will have randomized numbers. However, the root instance name is always the same.
QUESTION: What would be a good strategy for creating a function that will parse a list of these instances and, in a new column, list all duplicates past the second copy? In relation to the example above, the new column would list:
cdemultipleinstanceexample0003
cdemultipleinstanceexample0004
I need to have the two duplicates with the lowest integer values preserved out of each set of duplicates, which is why in the example above 3 and 4 would have to go. So in the case of randomized numbers, the two instances with the lowest integer values.
What I have thought of
I was thinking to first organize the column by alphabetical order, which should automatically put duplicates in ascending order. I could then basically strip the number value from all instances, and find where there are more than 2 exact duplicates from the core instance name, which would give me the instances with more than 2 duplicates so that I could perform a function on the original data set... but I don't know if there is a better way of doing this or where to go from here.
I'm looking for formula-based solutions.
Assuming your sorted list is in Column A and that you have a row of headers you could use the following formulas in the neighboring columns.
In B:
=LEFT(A2,LEN(A2)-4)
In C (although not really necessary):
=RIGHT(A2,4)
In D starting with row 3:
=IF(AND(B3=B2,COUNTIF(B1:B3,B3)>2),"Del","Keep")
This formula doesn't work in row 2, but you can hard code the first result.
Then filter the list on Column D for "Del" and delete all the rows.
How's that?
Sort your list in column A. You'll want column headings for later so put those in row 1 (or leave it blank. In B2, type =left(A2,len(A2)-4) and drag the formula down to strip the integers. In C3 type =vlookup(B3,$B$2:$B2,1,0). Populate the formula in C3 right one cell and then down the length of the data. Now in D3 you'll have a list that has errors for any entry that only 2 or fewer instances and will have the name for any that have 2 or more. Sorting this list with a filter on row D for #NA will allow you to delete all the rows with less than two entries.
Remove your filter. Then resort the list in column A in reverse order so the high numbers are first. Replace the contents of C2 and D2 with #N/A. Refilter the list on column D for everything but #N/A and delete all the entries that have an instance listed.

Sort one column to match another in excel

I have a spreadsheet and I need to match the two columns together. However "Dove code" is 3600 rows and "code 2" is 1100. They all have the same codes as you can see in the image but you can also see where it starts changing and I need to have the codes all line up so I can see the gaps. I have already arranged them all alphabetically and its the "code 2" that would need to match up to "Dove code
If the above solution would result in too much shunting and vba is not an option, there's another way. Copy the first column and use 'remove duplicates' on it. Now you have an index list, put numbers from 1 to x in the column on the right of it.
Insert a column between the two lists and right of the second one.
Assuming that the index list is in F and the numbers in G, put this formula in the cell right of the first cell in the larger list:
=VLOOKUP(A2,$F$2:$G$500,2,FALSE)
Adjust the range accordingly. Put the same formula in the cell right of the first cell in the shorter list, with of course C2 instead of A2. Copy both formules to the end of the list.
Now both columns have an index on every row. You can match them using data sort, but for that you need to add dummies in the index columns.
Put this formula in the cell right of your basic index list: =countif(B:B,G2)
And this one in the cell right of that: =countif(D:D,G2)
Now you know how many times each record arises in both lists. Just add extra numbers manually so that both formulas turn up the same result. You should be able to do that really fast. If you have 200 records that are used 2 times in the first column and not in the second one, just copy the index of those 200 records and paste them twice. The countif's will automatically update.
You can use an extra column to calculate the difference between the two counts and use data sort on your basic index list to sort on the diferences.
After that just use data sort.
IF my directions are clear enough, this shouldn't cost you more than 10 minutes.
Edit:
Here's an example: http://img14.imageshack.us/img14/6366/k8pg.jpg
Without VBA I do this (for columns with a limited number of mismatches!) by adding a formula such as =INDIRECT("A"&ROW())<>INDIRECT("B"&ROW()) in a helper column. Working downwards, every time you see a TRUE shunt the appropriate column down to suit. But it may be only just about viable for 1100 rows!

HOWTO ad a unique id to each unique row?

I have data in two columns:
a 1
a 1
a 2
b 3
b 4
In the list there is 4 unique rows. I would like to ad a unique id to each unique row.
Like this:
1 a 1
1 a 1
2 a 2
3 b 3
4 b 4
Of course I have many more rows and columns and date are more complex than in this example.
Anyway to do this i excel?
Mvh Kresten Buch
I have the same issue, I have developed a three formula approach to this. I could probably concatenate it if I nested them, but whatevs, this works.
Assume the data you want to 'number' is in column A, and the first row of the table is row 3.
The first column (in column B) counts occurrences of the 'value' and the range expands from the top of the table downwards as the table grows:
=COUNTIF($A$3:A3,A3)
the second column's formula also expands as the row count does, and simply adds 1 to the transaction count every time it encounters a 1 (ie first occurrence of a new unique value) in column B
=IF(B3=1,MAX($C$2:C2)+1,"")
This one worked for me even in the first row of the table btw - i was expecting to have to manually input a 1 to start the list. Having it work without the manual entry is a good thing, it means the formmulas all work even if you resort the table data into a different order.
The third one in column D uses a vlookup to find the value. Note that when vlookup finds more than one number, it always pulls the first occurrence.
=VLOOKUP(A3,$A$3:C3,3,FALSE)
Note that this will renumber all the data outcomes dynamically if you do resort the entire thing. ie the formulas all work, but the number 'assigned' to a praticular set of data might be different, as it all works from whatever order the list of items is in.
My use case for these formulas assumes that every month i paste a new set of data to the bottom of the table, some items of which are repeats from previous months - ie are already in the table, and some of which are new.
if the dynamic renumbering is a problem, use a 'row key' so you can resort back to the original order at the end.
Assuming your data is in B2:C6 please try =IF(AND(B1=B2,C1=C2),A1,A1+1) in A2, copied down
If your data is not sorted, it's more complicated... but you can use something like this in A2:
=IF(COUNTIFS($B$1:B2,B2,$C$1:C2,C2)>1,INDEX($A$1:A1,IFERROR(MATCH(B2&"-"&C2,$B$1:B1&"-"&$C$1:C1,0),1)),MAX($A$1:A1)+1)
I'm assuming that there are no headers and you have already put 1 in cell A1 for the first record.
It basically checks the whole columns above the formula and if there's already a similar record, it'll assign the previously given unique ID and if not, it'll give a new ID.
This is an array function and as such will work if you use Ctrl+Shift+Enter and not Enter alone.
The IFERROR() is there because MATCH(B2&"-"&C2,$B$1:B1&"-"&$C$1:C1,0) would return an error if it is on row 2 (the first record to check).
Once you put that in the first cell, you can fill down the formula.
I deal with this issue all the time when structuring a data set into panel data. say you have multiple columns of data, and each are unique based on the name of someone, like:
ANNE
ROSE
ANNE
FRANK
TOM
ROSE
ANNE
but instead of having each column related to Anne, Rose, Frank, or Tom, you want it to look like this:
1 ANNE
2 ROSE
1 ANNE
3 FRANK
4 TOM
2 ROSE
1 ANNE
So that each name now has a unique numerical identifier that can be used in place of the name.
Make a pivot table of your data and only place the column that has the names (or whatever the identifier may be) into the Rows section. This will single out all the different names used within the dataset. Copy and paste this pivot table anywhere on the sheet so that the names are in actual cells and not off of a pivot table. To the right of the names, enter 1 next to the first name, and then =B1+1, and so on so that you number each name with a unique value; then copy and paste this column as numbers so that their formulas are erased. Finally, just go to your original dataset and perform a VLOOKUP so that the names get attached with whatever unique value was assigned off of the pivot table. Make sure to copy and paste as numbers once done to remove the VLOOKUP formula.
Takes literally 2 minutes to do, depending on size of dataset, and is very easy. It will work perfectly every time.

Resources