Copy multiple cells from two separate sheets based on input - excel

I have three sheets:
I manually copy values from column A in Sheet 1 into column A in Sheet 3 and from Column A in Sheet 2 into Column B in Sheet 3 (as shown in the attached images).
The values are selected based on Column A and Column E. E.g. in Sheet 3, Q001-1 S1 from Sheet 1 is copied with G001-3 S3 and G002-2 S2.
I would like to simplify this process as much as possible because it is time consuming- however I cannot find a way to do this.
Is this even possible, using formulas or VBA??

if i understood correctly you need to perform a join in Excel using the cell ID as a criteria.
I'd use Power Query instead of VBA because it's the tool made just for this kind of task:
Select the original table and format it as a table (Tab Home) -
perform this operation for both data source
Format as a table
Load both tables into PowerQuery (click on the table and then go to Data/Get and TrasformData and select From Table PowerQuery repeat this step for both tables
From the table 1 select the tab Home select Merge, then choose the cell ID as a criteria (use the default left join) Join
Click on the new column to spread the data, remove uneccessary columns
Close and load (top left) your query into a new sheet (sheet3) - Load only the output table and not the original tables since they aren't necessary
To automate the process simply add new rows to the original tables and then click into the tab Data and then Refresh all. The results will appear into sheet3
I hope it helps!
Emanuele

If your plan is arbitrary or based on criteria that can't be determined mathematically, it can't be solved with code alone. If you'd like to plan your arrangement on a 4th sheet, however, you can write conditional formulas in each cell on sheet 3 that evaluate your plan on sheet 4 and compare them to the cells containing the strings S1, S2, and S3. In cell A2 you could paste the following;
=IF((EXACT(Sheet1!E2,Sheet4!A2)),Sheet1!A2,IF((EXACT(Sheet1!E3,Sheet4!A2)),Sheet1!A3,Sheet1!A4))
It's evaluating the corresponding cell on sheet 4 for an S1 or S2, if it sees neither, it assumes S3. It then chooses the corresponding cell on sheet 1. The code in column B evaluates the corresponding cells on sheet 4 using the same trick;
=IF((EXACT(Sheet2!E2,Sheet4!B2)),Sheet2!A2,IF((EXACT(Sheet2!E3,Sheet4!B2)),Sheet2!A3,Sheet2!A4))
It then chooses the corresponding cell on sheet 2. You can drag these cells down as far as you need.
I wrote a working model and posted it to GoogleDocs

Related

In excel, how can I automate a sheet to be filled based on conditions of another sheet?

Is there a way in excel to copy the contents of one column to another sheet based on particular values in another column.
I have data which looks like this:
Sheet1:
Sheet2:
I would like to copy the column A of sheet 1 directly onto column A of sheet 2, but only if the value in column B is Y.
I have tried used the match function but am not sure how the best way to do this would be. Is there a way for me to achieve this?
My desired output is:
As discussed in the comments, #Waldorf99 was looking to have a second worksheet that would automatically show a filtered list from the first sheet. I can think of a few ways to do this (array formulas or pivot tables come to mind). The problem with mixing dynamic columns with static values is that the static values would become desynced from the dynamic ones.
In the original example, rows may have a blank value in the condition column in sheet one, and then may be assigned a Y or N at a later date. If a Y is assigned to a row in the middle of other rows, the filtered sheet would shift the existing rows down to make room. The static values would stay where they were, and would become desynced. To demonstrate:
If the above image is the original state of sheet 1 and 2...
...adding a y next to x.1.c would result in sheet two shifting columns A and B of row 2 down, but leaves columns C and D behind (as they are static, and not tied into the first two columns in any way).
One thing that may work as you are wanting are filters. You would only have one sheet, with all of the data manually entered. Then you can add filters, and change them to hide rows temporarily when needed.
To add and use filters:
Start with your data all on one sheet...
Highlight your data...
On the Home tab, select "Format as Table" and choose any style...
This turns your data into a table. You can filter by clicking the drop down in a given columns header row, then deselecting the values you want to hide.
The results are a table that only shows the rows with a 'Y'.
The other rows aren't removed, just hidden. You can always reset or change your filters, to configure which rows are visible.
Note: when working with tables, they will auto expand to account for new rows, so long as you work in the row directly under the table (e.g. don't leave blank rows). You can also manually resize the table at any time by clicking and dragging from the bottom right corner of the table.
There are tons of resources of Excel tables online, and it's a pretty useful tool in Excel.
Hope that achieves what you were looking for.

Excel Creating New Sheet with Summed Data from related sheet

Lets say I have the following on a sheet.
By some means, I want to either replace this, or preferably, create a new sheet, with the following data. Notice, that PO# is out of the picture, and a summation is done on rest of the fields. Is there a way to easily do this?
The end result has to be data in excel grid like below (preferably on a new sheet). This can possibly be some macro or some other technique I can use to easily create this....
You can easily do this with SUMIFS() or a Pivot Table.
For SUMIFS() the below equation will give you the sum for W.PS123 Product A. Modify as needed for your other criteria by swapping AR and product number (both housed in quotes in below formula, you can also set these equal to a cell range that contains desired criteria).
If you have a set number of "ARs" and Product Numbers, you will only need to build this table once and the equations will automatically update as your raw data changes.
=SUMIFS(C:C,A:A,"W.PS123",E:E,"A")
Alternatively, you can build a pivot table and just refresh this every time your data updates (or create a worksheet_change macro to refresh the table automatically when your data changes).
To build your pivot:
Highlight your table array (In your example, Col A-D)
Insert > Pivot Table
Drag AR to Rows
Drag PRODUCT to Rows (Below AR)
Drag QTY to "Values" and change the field to "Sum" rather the default count
Format to taste

Excel apply formula after pasting table

Is there a way to create an excel template, which automatically applies a formula if a certain column is inserted? The use case would be:
User copies a table from a desktop program (CSV or Tab separated)
Pastes the table into the excel template
Somehow the column's header gets matched (header's name is fixed)
Multiply the column values with a fixed value (like 1.25)
The problem is that the column could be in different indexes and the formula should apply to all the rows, not just fixed ones, but my main problem is how can I get a copy-paste event and find the column.
Edit.: I can only do this with VBA (never used it before)?
Assuming the column header is constant you could insert a table with "dummy" headers and a calculated column using the header name as a reference
In the example I have put a formula in the Calc column. I've put the Calc in column G assuming your maximum import columns are six and because it's good practice to do your calculations from left to right.
You could move the Calc to column A and reduce the "dummy" columns to just 1 with whatever your desired heading is.
To make a template, delete row 3 and clear out the dummy data, just leaving the calculation(s) and save as a .xltx in your profile template folder (wherever that may be in your versions of Windows/Office).
When you paste in your import data the table will extend down and copy the formula(s) automatically. If you have moved your calculation(s) to the left of the table, the table will resize to the right to accommodate all your imported columns.
While the MyHeader column in your template may be over-written, if it can still be found in `Table2[#Headers] the formula will still work.

Excel 2007. How can I convert names into unique IDs?

Currently I am forming a dataset in excel. With the dataset, I am going to do the panel regression using stata(fixed effect model).
However, I cannot change people's names into their unique IDs. In my dataset, I have name in column B, and I want to generate a new column A with corresponding numbers to names in column B. Doing manually is not an option for me since the number of data is larger than 1,000. Two particular problems I encounter are that names are in Korean so the number of characters are mostly the same, and there are same people in different rows. Is there any method that I could use?
If I understand you question correctly, I would do following.
Step 1: Used the Advanced Filter to filter on unique names
You can place these results on the same sheet or on a different sheet (as per Scott Craner's comment). Both options are listed below
Filter Names on the same sheet
Select all the data in column B, then click Data > Sort & Filter > Advanced.
Select the option to Copy to another location, Select a blank cell in column B location at the very bottom of your worksheet, several rows away from your data (since you won't be able to paste the results to a new sheet), and then select Unique records only. Then Click OK
Filter Names on a different sheet
Add a new sheet and the click Data > Sort & Filter > Advanced.
Select the option to Copy to another location
Set the "List range" to the column on your dataset sheet containing the names, and Set the "Copy to" range to B1 on your new sheet
Select Unique records only and then Click OK
This will paste a new range that has all the unique names in your list.
Step 2: Assign unique IDs to the names in the unique list
This can easily be done by entering '1' in the Column C cell next to the first name in the unique list, '2' next to the second name, selecting those two cells, and then clicking the bottom right corner of the selected cells and dragging it down to the bottom of the unique names list
Now you have a range (i.e. unique names and IDs) that you can use VLOOKUP to populate an ID column in your data set
Step 3: Use VLOOKUP to populate IDs for the rows in your dataset
For example, If your unique names and ID is in the range B1200:C1500, then you can enter the following formula in the first row of your dataset in column A (what you want to be the column with your unique IDs)
=VLOOKUP(B2, $B$1200:$C$1500,2,0)
After you drag this formula down your entire dataset, you'll now have the correesponding unique ID for each name.
Step 4: Cleanup
Copy your column A (should be all VLOOKUP formulas) and paste Values only so you don't have the formulas there anymore
Delete the unique data and IDs range at the bottom of sheet (or the new sheet you created to do this)

Excel Data Validation List using formula with filtering

I have following workbook:
Worksheet Accounts:
Worksheet Posts:
I would like to know if it is possible to define Data Validation of type List to entire column B in sheet Posts using formula, so that Data Validation popup shows only Account Ids from Accounts sheet which Website column matches Website column of a selected row in Posts sheet and which have value Active in Status column?
In SQL-ish or LINQ-ish words:
SELECT Id FROM Accounts WHERE Website =
#SelectedPostRow.Website AND Status = Active
Marks on the second image shows which values should be shown in a drop-down.
Yes you can do this, but it requires some supporting setup.
First for each of your website options, you need to create a named range for the options that would be in the drop down you are seeking to create.
To do this, just highlight the list of cells and right click, the choose Name a Range
Then you need to create a lookup list for your website names to the named range possiblities
Then in your data validation source use a forumla like this:
=indirect(vlookup(a1,$i$8:$j$13,2,false))
then whala, the dropdown list changes based upon the website value.
Now if you are also needing to automate the named range bits, you could change them to encompass entire columns and then use a pivot table to pull in the data. Would just need
an independant pivot for each website option.
Each time you pulled in fresh data you would need to refresh the pivots, but it would function.
This problem need a bit of a preparation.
In the same sheet, or in another, copy your data (or add the relevant cells)
In column A you have a number that could be ranked.
I obtained it with (cell A2):
=IF(C2=$J$2,1,0)*IF(E2="Active",1,0)*ROW()
In column B rank the number and exclude the unwanted rows (B2):
=IF(A2=0,0,RANK(A2,A:A))
Then you can VLOOKUP in column H, using a enum in column G (manually entered). The formula for H1:
=IFERROR(VLOOKUP(G2,$B$2:$D$9,3,FALSE),"")
Now you could set your validation based on column H
PS: there could be small errors in the formulas as I have translated them from italian and I cannot test in english.

Resources