Merging Columns - vba

I have data from column 'D' to 'N' that I want to merge into one column without losing the data. I have tried this using the 'Merge Cells' option in the Home tab but then it discards all my data.
Is this possible to do in VBA?
Functions are of no use to me by the way.

Insert column after N if not already blank
Enter formula =CONCATENATE(D1,E1,F1,G1,H1,I1,J1,K1,L1,M1,N1) in O1
Fill down
highlight column O and copy
right click column O and select select paste special then values
Delete columns D-N O is now your merged column and after delete is in Col D.
Assumption here are:
there is no other data in D:O that you care about.
having one column with all data is acceptable, you don't need the outer cells to remain independant.

Related

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.

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

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.

Creating a join list between two tables VBA

Good afternoon,
I am still quite a novice with VBA but am trying to create a loop that will be able to sift through a long list of data within a given column (in my case, both tables have one common identifier, the system ID) and if a system ID is matched in one column with a column from the other table, then a new sheet is created that combines all of the rows associated with both sets of data into one row.
For example, if my data looked like this:
Table 1
Column A, Column B, Column C |
ID, Name, Birthday
Table 2
Column A, Column B, Column C|
Purchase, Amount, ID
And I had the same ID in both Tables 1 and 2, for each match, I would like to have all rows associated with the match joined together.
This would really enable me to speed things up with organizing information, so I was not sure if it would be possible... Any Ideas are welcome!
since excel is not a database program like access, you can not use sql-like joins natively. you would have to program your own join function:
(Since i do not have MS Office installed, i can only give you pseudo-code)
for each-loop going through IDs of Table1
for each-loop going through IDs of Table2
if(Table1.ID = Table2.ID) then
copy data of Table1 into a new sheet
copy data of Table2 into the same sheet, next to Table1 data
PS: i assume you use excel because of the vocabulary (column, worksheet,..)

Replacing a value in an Excel column, based on its value in another sheet

I have a exported Excel sheet from SQL with records for insurance policies held by vendors that visit our office. There are two separate tables that identify the Insurer and the Vendor by a code. The table with the records of all the policies just has the codes for both of them.
Is there a formula that can look at another sheet for a value, and pull in another column from that sheet? Basically there is a key code for each vendor, and I need to replace that code with their actual name from another excel sheet.
Or if there is a simpler way to do this in SQL I could try that too.
In SQL you can JOIN the tables together:
SELECT i.col1,i.col2,v.col1
FROM Insurer i
JOIN Vendor v
ON i.key_code = v.key_code
Adjusting which columns you return as needed, without sample data it's unclear if there needs to be additional criteria in the JOIN.
In Excel you can use VLOOUKUP(), but I prefer INDEX() and MATCH(), below would try to match the value in B1 to a value on Sheet2 in B1:B20, and return the value from the corresponding row from Sheet2 A1:A20:
=INDEX(Sheet2!$A$1:$A$20,MATCH(B1,Sheet2!$B$1:$B$20,0))
There are numerous illustrated examples of either excel method that will be easy to follow.

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!