This is probably a very trivial question for an Excel expert, so I apologize in advance. I spent hours on this, but as everything in Excel -- unless one is an expert in it they will probably find quantum physics easier.
I have a workbook with a sheet which needs to pull data from another sheet. There are two lookup criteria:
A row-based lookup on the other sheet, which is working and finding the corresponding row.
In the corresponding row on the other sheet, I need to grab a value from a cell in that row based on a dynamic column name. So I have a string-based name of the column (i.e. the header; i.e. row #1), and I need to grab the value from the it based on the column's name.
Here is my lookup code and what I am trying to do:
=XLOOKUP(
// Source data for row lookup (working)
D3&H3,
// Destination data for row lookup on other sheet (working)
'Prices'!$A$2:$A$1048576 & 'Prices'!$B$2:$B$1048576,
// Not real code, but the part that I am trying to accomplish.
// The CUSTOM_COLUMN_NAME will come from either a formula or
// another cell on the given sheet, and is supposed to denote
// the column header name on the Prices sheet.
'Prices'["CUSTOM_COLUMN_NAME"]:$2$1048576
)
(I provided the entire function just in case it would be easier for someone to rewrite it with VLOOKUP or HLOOKUP)
Hopefully this makes sense, and any help would be sincerely appreciated...
Here's an example of 2-d look-up using MATCH and INDEX, and it will work across sheets.
Related
My question must be very basic, but I'd like to ask it anyway.
How can I "tag" values in a column of one sheet (to be exact, those are Purchase Order numbers) so that another sheet can assign its own value ("received") based on that tag? It seems that there should be some condition-based rule.
I will be grateful for your help!
I'm not totally sure what you mean, but assuming you want the values in one sheet to sum based on the values in another sheet - then yes this is pretty easy.
Add this formula to the sheet you want to do the counting in
=COUNTIF(OtherSheetName!C:C,"Purchase order")
If you mean that you want each individual cell to change, rather than deriving a total, then you must have some way of matching the cells in one sheet to the other sheet.
I have a rather large excel sheet 20k+ rows. My excel document has three sheets named CM, PP, and CH.
CM only contains the Information I use.
PP is the public Information that contains ALL data.
CH is my change log.
What I'm trying to do is take the values from my CM sheet in Column A "CM(A)" and find them in the PP sheet Column A "PP(A)", then copy the found values from PP(A) and PP(F) "The sixth column over" to the third sheet CH(A) and CH(B).
This in of itself is rather simple, where I'm having a hard time is that sheet PP can contain multiple instances of the value in CM(A). The catch though is that I only need One of those specific values which is indicated by a value of "26" in column PP(B).
I just have no idea how to write the nested formula to make this happen.
Visual Goal of Formula
If you're unfamiliar with Array Formulas, you should definitely look into those as they are extremely helpful for tasks like this. You would need to use a conditional to test if the item occured more than once and then execute an INDEX-MATCH or VLOOKUP based on the results returned. I recreated your data structure and was able to achieve appropriate results using this formula in B1 of sheet CM:
=IF(COUNTIF(PP!A:A,A1)>1,INDEX(PP!F:F,MATCH(1,(PP!A:A=A1)*(PP!B:B=26),0)),VLOOKUP(A1,PP!A:F,6,FALSE))
Array formulas must be entered using Ctl+Shift+Enter, as is noted in the linked documentation.
I have a spreadsheet that will occasionally get new data that I don't know the contents of, I just have to add it to the spreadsheet. Some of the new data is just updating rows that are already in the spreadsheet, and other data is adding new rows. I'm looking for a way to add a column that will tell me if something has changed in the row when I compare the old spreadsheet to the new one.
The sheets have one column that will always have a unique value among all the rows, so I can use that to match rows if the sheets aren't sorted the same way. Here are some screenshots to show what I'm trying to do:
Old Spreadsheet:
New Spreadsheet:
The only solution I can think of is a large nested IF formula that compares each column one by one, something like:
=IF(Old!B2=New!B2,IF(Old!C2=New!C2,"NO","YES"),"YES")
The problem with that is that it gets very hard to look at since my actual data is using 33 columns (not including this "Changed?" column) and new columns could be added in the future.
I'm not very technical with Excel, nor have I ever used VBA, so I apologize in advance if there is a simple/obvious solution that I'm missing.
Thanks in advance for your help.
Using your example, in the 'New' sheet cell D2 and copied down:
=IF(COUNTIF(Old!A:A,A2)=0,"YES",IF(SUMPRODUCT(COUNTIF(INDEX(Old!A:AG,MATCH(A2,Old!A:A,0),0),LEFT(A2:AG2,254)&"*"))=SUMPRODUCT(COUNTIF(A2:AG2,LEFT(A2:AG2,254)&"*")),"NO","YES"))
vlookup would also work well for this problem.
in D2, the formula would be:
=IF(AND(VLOOKUP(A2,Old!A:C,2,FALSE)=B2,VLOOKUP(A2,Old!A:C,3,FALSE)=C2),"NO","YES")
The column numbers (2 and 3) are the columns that correspond to the data you are trying to match, using the ID column.
It's possible to find the appropriate column using MATCH if the column names you have match the column names in the old sheet
This would make the formula look more complex, but Excel would adjust the Old!A:C reference if more columns are inserted.
The formula would look like this to match against column names
=IF(AND(VLOOKUP(A2,Old!A:C,MATCH($B$1,Old!$1:$1,0),FALSE)=B2,VLOOKUP(A2,Old!A:C,MATCH($C$1,Old!$1:$1,0),FALSE)=C2),"NO","YES")
The difference between this and the last one is the use of MATCH($B$1,Old!$1:$1,0) to find the column (using $s to anchor the lookup values)
In this case, specialized software for Excel compare is better.
My company use this software. Check it out.
http://www.suntrap-systems.com/ExcelDiff/
http://www.youtube.com/watch?v=QQgnWr_RT-8
I've been looking for hours to solve this but I just can't find an answer.
I have an excel table, and I have another sheet with a partial copy of that table.
Now what i want is when I add a row in my first table (Please note that there is also text below this, but I can put a mark there or something similar to mark that it should end there), that my other table would also add the same amount of rows (Also please note that my second table has text below).
I have no idea how to do this, what would be the best approach?
I'm not even sure what I ask is making sense.
So let me try again in different words:
Sheet 1:
Some text
My rows
Some text
Sheet 2:
Another text
My rows
Other text
if i add rows in sheet 1, i want them to be also added to sheet 2.
Is this possible?
Thanks a lot guys
A possible solution would be in C#, where you actually after you insert data in one sheet to replicate the same table content or a copy of that sheet into the destination sheet. Or by copytoclipboard, you take the any table and copy it to the desintation. Which solution are you looking for? C#, VBA?
sheet.UsedRange.Copy(Missing.Value);
sheet.Range(cellmapp).PasteSpecial();
Where cellmapp is the range where you want it to replace. If you text is to huge for the area, you can use sheet.Columns.AutoFit(); sheet.Rows.AutoFit(); This would be a C# solution, but would require a bit more of programming.
And for looping through the sheets:
foreach (Excel.Worksheet sheet in workbook.Sheets)
{
workbook.Activate(); sheet.Activate(); foreach (Excel.Shape shape in sheet.Shapes)
{ }
}
For the row, modification or switching place, you can simple move all your existing row values from one position to the right possible if you create a new row.
sheet.UsedRange.Copy(Missing.Value); //copy your existing row's
sheet.Range(cellmapp).PasteSpecial(); // move them from B4 to C4
I need some help with a macro/vlookup. Originally, I recorded the macro and just did the VLOOKUP manually thinking that would always work. Lately, it hasn't been functioning properly (and I'm not sure why except that it's possible columns are not always in the same place from time to time). Is there a way to write this macro out so that it will work each time?
Here is what I'm trying to do:
I have a master spreadsheet and a vacancy spreadsheet. The master spreadsheet has information that I need to move to the vacancy spreadsheet. Not everyone on the master spreadsheet is listed on the vacancy spreadsheet (and vice versa) nor is either in a specified order. I already have a macro that adds the column names I need to the vacancy spreadsheet so that's set. I just need to get the information in there.
I want something that does the following:
Take the employee number from the vacancy spreadsheet and search for it in the master spreadsheet, then copies the information from specific column names (off the Master spreadsheet) into the columns (of the same name) on the Vacancy spreadsheet
Ex: employee number 12345 is on the vacancy spreadsheet. The macro searches the Master Spreadsheet for employee number 12345, then moves the information (within the Master Spreadsheet) from the columns Category, Center Name, Job, Location, Code, Tracking, Reason, Salary over to the columns of the same name on the vacancy spreadsheet.
There are many more columns that I need the information from, but that's a sampling. These spreadsheets are huge with tens of thousands of rows of data. Any assistance you can offer would be greatly appreciated!
I hope this all made sense.
Edit based on workbook file examples
In the SAMPLE Milestone Report.xlsx file, column M, place the following formula:
=INDEX('[SAMPLE Master Active.xlsx]Sheet1'!$1:$4,MATCH($A2,'[SAMPLE Master Active.xlsx]Sheet1'!$A:$A,FALSE),MATCH(M$1,'[SAMPLE Master Active.xlsx]Sheet1'!$1:$1,FALSE))
You can then copy & paste this formula across the remainder of the rows/columns. Some of them are going to return #N/A because the column labels don't match exactly. A similar error would return if the Employee Number could not be found.
The Index function refers to rows 1:4 of the Master Active workbook, sheet 1.
The next argument uses the MATCH() function to find the row # of the employee number in column A of the Master Active Workbook, sheet 1.
The next argument uses the MATCH() function to find the column # of the column label, in Row 1 of the Master Active workbook, sheet 1.
So this way we are able to refer to the range containing all data in your Master Active workbook, and dynamically identify the ROW in which the employee number exists, and the COLUMN in which the column label exists. The Index function then returns the value from this intersection.
Original Answer
The VLOOKUP function requires three arguments with an optional fourth argument.
Lookup_Value - this is the value you're searching for
Table_Array - this is the range/table in which you're searching for lookup_value
Column_# - the formula will return the value in matching row, for this column #, within the table_array.
Range_lookup (optional) - tells Excel whether to return an approximate match or an exact match. I have never needed to use approxiamte match, so I always set this to False.
What you need to do is make the Column_# a dynamic value, based on some other criteria. You can probably do this with the MATCH() function.
The following examples use worksheet function conventions, but shoould easily translate to VBA.
=VLOOKUP("steve", "A:C", 3, False) will return the value in column 3 from the row where "steve" is found in column A.
But assuming your data will not always be in column 3... lets say you are looking for "Category" and it might be in any column, but you know that the ccolumn labels will be in row 1. Then, instead of "3" in the VLOOKUP... formula, you would do:
Match("Category",'Vacancy_Sheet_Name'!1:1, False)
so your end resulting formula would be:
=VLOOKUP("steve", "A:C", Match("Category",'Vacancy_Sheet_Name'!1:1, False), False)
In vba, this would be:
= Application.WorksheetFunction.Vlookup("steve", "A:C", Application.Match("Category",Sheets("Vacancy_Sheet_Name").Range("1:1"),False), False)
An important note: With VLOOKUP it is ALWAYS looking in the first column of Table_Array for the Lookup_Value. If the structure of your data has changed, and the lookup_value is no longer in the FIRST column, VLOOKUP is not the appropriate function to use. In cases like these, it will probably be necessary to use a combination of INDEX() and MATCH() functions, because VLOOKUP will not work.