Table of data want to group, transpose matching values same line - vba

I have a table of data in Excel. Column A contains Names, Column B contains their interest. Each interest has a separate row. I want to take the data from this table and have a single row with the name of the customer and a column for each of their interests. IE RAW Data:
I am looking to take the 4000 row table and grouping by the name. I am unsure how many times each name appears in the list (Once or Fifty times) but I want the interests placed on a single row with each interest in a separate column EG Desired Data:
I have tried the standard transpose....html table....and pivot tables but it will put the interests all in a row along the top regardless if the customer is interested or not and using a record count T/F that means the data sheet in harder to understand then if I leave it as one block and sort by name
Sure I am not alone with this but all searches for the past 2 hrs keep returning pivot/transpose or duplicate items. Any is appreciated

If you don't want to use VBA, you could first add a column, for instance in column C, with the title "InterestNum."
In C2, just put 1.
In C3, put =COUNTIF($A$2:$A2, $A3) + 1. This will find the number interest it is for the person.
Make a lookup column, for instance in column D. In D2, put =A2&C2
Then, make a list of all the people. I assume that you put this list starting in cell A2 of a new sheet. Then put headers starting in B1 so that B1 contains the title "1" and C1 contains the title "2" standing for the interest number and as many columns as you wish.
Then in Cell B2, put the formula =IF(ISNA(MATCH($A2&B$1,data!$D$2:$D$5,0)),"",INDEX(data!$B$2:$B$5,MATCH($A2&B$1,data!$D$2:$D$5,0)))
This assumes that your original data is in the data tab. I only tested with 4 rows, so you would need to change $D$2:$D$5 to have as many rows as you do. This works by looking up a combination of the name and interest number. It first checks to see if that combination exists in the data. If not, it leaves that interest blank. If so, it finds the actual interest by going to the same row of the lookup.

First remove duplicates using standard excel functionality to prevent having the same interest twice for a person.
Now, you could of course use VBA and perform exactly what you need.
However, I suggest that you use the pivot table.
If your data looks something like this...
... just use "Insert | Pivot table" and insert a pivot table to a new worksheet.
Then, configure the columns as follows:
Et voilĂ , there you have all your interests listed only once and if a person shares an interest, there is a "1".
If you would rather use VBA, just comment and I will edit my answer.

Related

How to identify a repeat column in postgreSQL, where the column has random input

I have two columns. ID, and Transcript. The numbers in the ID column are randomly generated. The Transcripts in Transcript are from an array that I cross-joined and unnested, which has generated several repeats of "ID" in Column 1 whenever there's multiple transcripts per ID.
I can't use the usual stack overflow "if" statements. The numbers in the ID column are randomly generated (and there's thousands of them), so I can't just write "if column ID is 'apple', then-."
I have to automatically identify when & where the column has a repeat, and then be able to take the second (and third, if there is one) rows, isolate the unique data in those rows, then append them onto the first row, in a new column. (I'm aware this would generate "null" data in other data rows' columns that don't have the new data. I presume I'd have to create new columns, pre-filled with '-' in them?)
I'm new to SQL, but does 'count' just tell the user the number of repeats for a particular input that the user specified?
Is there any way to write that number into a new column along a specific row (e.g., 'original instance of this ID') so that I can then issue a command based on that number? Otherwise, is it just telling the user how often something has repeated and isn't machine-readable to be used in additional steps?
Otherwise, can I number the duplicated IDs, then I can issue an order. 'if 1, insert into new column 1 row above if filled with '-. Else, insert transcript on the row above in new column 1 if column 1 has data '-'. Else if, put in column 2. etc.,'
I'm entirely lost as to how to even get it to recognise the duplication is occurring in a meaningful way, given the random nature of the ID system.

VBA macro to loop through filter, Copy reference cell, and then paste in separate sheet

I have a table with source data in columns Sheet1!A6:R553.
In Sheet1!A3:R3, I have formulas that pull specific information out of my data table in Sheet1!A6:R553 that I want copied to a different sheet.
Column A acts as my project name column, while column B holds order numbers. In my case, there are multiple order numbers per project.
I am looking for a script to filter and loop through all the unique order numbers in Column B one by one, then copy cells A3:R3 to Sheet2!A12:R12 for as many rows as there are unique order numbers.
Example: Assume there are 5 projects in my data sheet. I will filter the data using another macro to select Project_1. I would then like a command button to active a macro that will filter to the first order number in Column B, copy Sheet1!A3:R3 to Sheet2!A12:R12, then filter to the second order number in Project_1, and repeat the process. This should go on until all unique order numbers have been filtered and looped through.
Thank you for any help you're able to provide.

Combining different tables in excel by looking up values

Okay, so let's say I have two tables in Excel. I want to create a third table that looks up data from the other two and combines them. I'll explain what I mean
Here is my first table:
It has a number, which is like a primary key, and a corresponding name for each entry.
I also have a second table:
This one just contains some random info, and there's numerous entries. The Client Name is not listed here, but it does have the key for the client that each entry corresponds to.
I want to create a third table that shows me all the Client Info data, but replaces the key with the actual client name. So basically, wherever it sees a key of "1", it'll look that up from the first table and find "Comet" instead.
The desired table would look like this:
What kind of formula would I need to pull data from one table based on a value? Note that all my tables are in different worksheets.
Assuming that the three tables are in Sheet1, Sheet2, Sheet3, this is the formula you need in Sheet3, cell A2
=vlookup(Sheet2!A2,Sheet1!$A2$b$6,2,false)
Copy down as many rows as there are rows in Sheet2
If you need the client info from Sheet2, use this in Sheet3, cell B2 and copy down
=sheet2!B2
As you put an "SQL" tag, I assume that you are also looking for an SQL based answer. So in addition to #teylyn suggestion, you can use the following SQL query if you are working with SQL databases:
SELECT table1.Client_Name, table2.Client_Info
FROM table1
RIGHT JOIN table2 ON table1.ID_Number = table2.ID_Number
Here is what this query does:
The RIGHT JOIN will return all rows from the right table (here table2), with the matching rows in the left table (here table1) according to the condition specified by the ON clause (here, if the ID Number is the same). Then, the SELECT clause will return a table with ONLY the columns specified after the keyword SELECT.

Excel Data table - preserve manual entries in one column

I have the following table layout in an Excel data table (fed by a SQL query):
Name, Birthday, Children, Check In
The first three columns come from a database query, the Check In column should be a column where I can manually enter an x for example.
Now, when I refresh the data table, the entries in the last column should stay in the right row. Currently, when I refresh the table the entries stay in the very same row they were entered in (e.g. if you enter an x into row 4, refresh and row 4 becomes row 5, the x stays in row 4).
Is there a way to avoid this?
Thanks in advance!
Hopefully you have some ID that uniquely identifies each item in each row (you could use the Name column if you don't have duplicate names). Keep a copy of your old data that you have marked the "Check In" box for. Then do a basic VLOOKUP to see whether that name has check in.

Copy information from one spreadsheet to another based on a single factor

A B C
1. c First Last
2. d First Last
3. e First Last
4. c First Last
5. c First Last
I'm trying copy the information from columns B & C over to another worksheet (tab in the same document) based on the letter in column A. I only want first and last names to be transferred if the letter in Column A is a "c". Is there a formula or macro I can use to do this?
I think the easiest answer is to create a pivot table based on on the data on your first worksheet. You can format the pivot table so that it looks similar to your original spreadsheet and then filter your column A to select only the letter "C".
One thing to be careful of, is that when you select your data range for the pivot table, be sure to select the entire columns. that way you can add more names and the pivot table will pick it up.
A couple of notes of concern in the pivot table options:
turn off the totals and subtotals to make the pivot table look more
like your original spreadsheet
set it to update automatically, so that you don't have to be constantly refreshing
Hope this helps!