Excel: Scanning column with multiple conditions - excel

I just started off as a new programmer and I'm trying to create Vba code to scan the following data in Excel.
Let's assume
Apple = 123456
Apple Juice = 987654
Pear = 234567
Pear Juice = 987654
Orange = 345678
Orange Juice = 987654
The codes for each item will be given but what I want is to write a program to detect the specific codes and assigning it the names (apple, apple juice etc.). If "123456" appears first, then the cell below it will be assigned "Apple Juice". If "234567" appears first, then it will be assigned "Pear Juice". It is challenging for me as Juice category shares the same "987654" unlike the Fruits which has a unique FruitNo assigned to it.
However, I am having difficulty writing the codes for the scanning of above cells. I have tried using the ActiveCellOffset but it doesn't seem to be functioning to the way I want it.
The following codes are what I have tried so far.
And this is the outcome I would like to have. The red letters are the names that the program is suppose to come up with.

Changing your code from
If FruitNo = 987654 And ActiveCell.Offset(-1, 0) = 123456 Then
to
If FruitNo = 987654 And Range("A" & i).Offset(-1, 0) = 123456 Then
should solve your issue (and same for another IF condition). However, this can be achieved using formula also.

Related

How to filter by distinct AND Max in Excel

hmmm. Thought this was like a normal forum. Ok it's not copying my highlight. I have complex and changing data sets this is a simple version. I want to some how filter the following:
state number seq OP
KY 831222 1 Apple
KY 831222 2 Apple
KY 831222 3 Apple
KY 845678 2 orange
KY 845678 3 orange
KY 845678 4 orange
KY 845678 2 Banana
KY 845678 3 Banana
KY 845678 4 Banana
PA 4567890 4 Apple
PA 4567890 5 Apple
So that I only see the following:
KY 831222 3 Apple
KY 845678 4 orange
KY 845678 4 Banana
PA 4567890 5 Apple
That is I want to filter/group by the MAX seq for EACH set. I THiNK if this was seq I'd do it something like this:
Select Distinct State,number,max(seq), OP From (table created from range) group by KY,number,OP
BUT how do I do it in EXCEL? I know there is a seq wizard thing but I can never get it to work right. Inbedding a sql query in a macro may be doable.
I am a little past beginner with macros. I generally record then figure stuff out later. So I may not understand terms.
OK This looks fine up here in the copy/paste write area but the "draft area" at the bottom looks like it's squishing things together. I don't have time to figure out how to format this so it looks like the table I'm seeing. I just hope this displays correctly.
Thanks for any help
- Sharon
Tried various types of filtering. Tried a pivot table - it just makes a mess - doesn't even display the data neatly. Tried the sql wizard but it's clunky.
Few steps:
Select your range > Data Tab > Sort
Add 4 levels of sorting: State - Number - OP - Seq
Only edit to make: Sort Seq from Large to Small
Apply
Keep range selected > Data Tab > Remove Duplicates
All boxes need to be checked but Seq
Apply
We need to first sort the range on Seq column largest to smallest since remove duplicates will work bottum-top.

Excel multi value counter

I couldn't find anything similar.
I have a pretty big excel table but I can't get what I need from it.
I have a column for example of names
John
Johnny
Arny
Arny
John
Johanatan
Jeremie
Brook
Arny
Johanatan
I want it to return or show me results like that
Johnny 1
Arny 3
John 1
Jeremie 1
Brook 1
Johanatan 2
Couldn't find an appropriate excel to result me with that.

How to sum a reference column with a custom ordering

I'm trying to sum a column that is from an input table to link to a reference table that a user can select inputs to create a "group." I think an example is better here:
Inputs
Key Type Name Count lookup_value
1 Fruit Apple 3 1 - Apple
2 Fruit Orange 5 2 - Orange
3 Fruit Pear 6 3 - Pear
4 Veggie Broccoli 3 4 - Broccoli
5 Veggie Celery 2 5 - Celery
The user puts these inputs in, and from another screen is able to customize a group (each of the selection is from a dropdown,lets call each array of data input_column name such as input_lookup_value for our formulas). Using the following formula in a cell next to "Total Pieces of Food,"
=sumproduct(--(A1:A3=input_lookup_value),input_count)
We will get the correct answer of 14, as below.
Group Name: Food Sally Likes
Total Pieces of Food 14
Item
A1 1 - Apple
A2 2 - Orange
A3 3 - Pear
However, if the user is to put in just Celery in cell A1, the formula will not work, and the "Total Pieces of Food" will return 0, since the order does not match the Input table order. Is there another formula or way I can attack this that will return the correct count, and still allow the user to enter the list in any order?
To put what #Jeeped (with his permission) suggested in the comments into an official answer:
The formula is:
=SUM(SUMIFS(Sheet16!D2:D6, Sheet16!E2:E6, A4:A6))
This is an Array Formula, So confirm with Ctrl-Shift-Enter

comparing two columns in excel (VLOOKUP not working)

I have been breaking my head with this problem since morning and I haven't found a solution. Please give your valuable pointers if possible, so that I can try to find the solution.
I basically have two sets of data- an old list and a new list. I wish to compare the new list( comparing name and country together) with an old list, since the new list has a few additional entries. Later on, I would like to create a new list with common entries from both old and new list and add all the new entries below the common ones ( if possible, else I will do that manually later on but I would like Excel to tell me that this is a new entry). Sorry, if this has not been well explained, but maybe the following illustration helps
Old List
Item No. Name Country
1 Apples Italy
3 Banana Spain
4 Grapes Slovakia
5 Pineapple Greece
8 Banana Czech Republic
14 Apples India
23 Pineapple Hungary
19 Peach USA
2 Strawberries France
New List
Item No. Name Country
4 Grapes Slovakia
Mango Pakistan
14 Apples India
Oranges Mexico
19 Peach USA
2 Strawberries France
1 Apples Italy
3 Banana Spain
23 Pineapple Hungary
Avocado Netherlands
Expected Output:
List with common serial No.s based on common names from both lists
Item No.Name Country
4 Grapes Slovakia
14 Apples India
19 Peach USA
2 Strawberries France
1 Apples Italy
3 Banana Spain
23 Pineapple Hungary
Mango Pakistan
Oranges Mexico
Avocado Netherlands
As can be seen in this attachment, I have an old list with Item No., Name and Country. Let's assume that the item numbers have been classified based on some code words. In the second list, there are again Item No.s, Name and Country but some item numbers haven't been filled ( since they are new and have not yet been sorted). Now, I want Excel to compare the names AND countries of both data and provide the common Item No. output if there is a match. If there is no match, then I would like Excel to tell me that this is a new entry. I looked up on various forums and I realized that VLOOKUP command only allows me to search on Name OR Country would give me the common entries of Names/Countries respectively but not Item No.s. Is there any formula that could help me solve this problem?
Just paste the list together, then sort it, and then remove the duplicates. Removing duplicates is built-in into Excel starting from version 2007, you will find it in the Data ribbon (see http://office.microsoft.com/en-001/excel-help/filter-for-unique-values-or-remove-duplicate-values-HP010073943.aspx).
To use VLOOKUP just concatenate Name and Country, for example, B2 & "-" & C2. You can then do a lookup on the concatenated values in your source table:
VLOOKUP(B2 & "-" & C2,NewList!D2:E100,2,False)
This assumes that the concatenated column is in D in your new table, and that you've copied the numbers to column E (VLOOKUP can't look to the right). I put in the dash for readablility and to avoid the chance that a Country ends with a number, unlikely as that might be.

Search & Concatenate? Find A String and Concatenate Value From Adjacent Cell into "Master Cell"

Here's how Data is laid out:
Company Ticket #
Apple 123456
Bestbuy 121457
Target 123458
Apple 123479
Target 123446
I need to Find Every Ticket # for apple, and place into a cell, ex: (123456, 123479)
I'm thinking I can use some version of search and the concatenate function to accomplish this. Have tried so far with no luck
Would prefer no VBA / pivot tables :)
You need an extra row to test it properly:
Company Ticket #
Apple 123456
Bestbuy 121457
Target 123458
Apple 123479
Target 123446
Apple 124
It's not very elegant but here goes:
In the last row (say row 7) in column C (C7):
=B7
In the row above in column C (C6):
=IF(ISNA(INDEX($A$7:C7,MATCH(A6,$A$7:A7,0),3)),B6,INDEX($A$7:C7,MATCH(A6,$A$7:A7,0),3)&", "&B6)
You have to do it backwards because match finds the first one going down that is a match.
Drag that formula up to the top row (C2).
The first row will of the company will have a list of all the ticket numbers separated by ", ":
Company Ticket
Apple 123456 124, 123479, 123456
Bestbuy 121457 121457
Target 123458 123446, 123458
Apple 123479 124, 123479
Target 123446 123446
Apple 124 124

Resources