Excel copy data from another sheet based on criteria - excel

I have 2 Excel sheets and I want to copy data from sheet2 to sheet1
when the data in sheet1 is the same as in Sheet2
I tried Vlookup and INDEX-MATCH and i couldn't get them to work
Sheet1
Sheet2
I want to copy the Nr from Sheet2"B" to Nr in Sheet1"C" When the ID in sheet1 is the same as in sheet2.
Thanks in advance

My data in Sheet2 is:
And in Sheet2 I got:
The formula I've used in Sheet1 in Cell C2 (and then drag down) is:
=VLOOKUP(A2;Sheet2!$A$2:$B$5;2;FALSE)

Related

Excel VBA get dynamic values from a source sheet to destination sheet

I am new to VBA and I have been trying this for a while but so far no luck.
I have a workbook with 2 dynamic sheets 1 and 2. Each sheet has Column A(Tag ID),B(ID variation),C(values). I want to copy column C from sheet2 into column D of sheet1 if values of Column A&B in sheet1 match A&B of sheet2. There is also a chance that sheet 2 might not have all the entries for samples and only a portion of sample names will be available.
Any help is appreciated.
If Column C is just numeric data, then you could accomplish what you're trying to do without VBA and just use SumIfs or SumProduct.
Insert the below formula in your sheet1 cell D1 and drag down.
=SUMIFS(Sheet2!C:C,Sheet2!A:A,A1,Sheet2!B:B,B1)
Also, if you have Excel spill range feature, you could use a dynamic formula that would self-populate as rows are added.
=FILTER(SUMIFS(Sheet2!C:C,Sheet2!A:A,A1:A999999,Sheet2!B:B,B1:B999999),NOT(ISBLANK(A1:A999999)))
It sounds like you could create references to sheet 1 and 2, and loop through one of the sheets, while checking existence of each entry in the other sheet, and copying the value over if A&B match.
It's been a while since I've written VBA and this is not a great solution performance-wise, but this might help you get started.
Rough Example (definitely not syntactically correct, and is missing assigning sheet1 and sheet2 to the actual workbooks):
Dim sheet1 As Worksheet
Dim sheet2 As Worksheet
For row In sheet1
For row2 In sheet2
If row.Range("A").Value == row2.Range("A").Value
If row.Range("B").Value == row2.Range("B").Value
row.Range("D").Value = row2.Range("C").Value

Partial Match in Excel

I have an excel workbook with two sheets with hundreds of row in each sheet.
Sheet1 contains "ABCESX42 - Port 1" in Cell A2.
Sheet2 contains "ABCESX42" in Cell A2 and "EMAIL" in B2.
I am trying to go a VLOOKUP in Sheet1 Cell B2 to do a wildcard vlookup on Sheet1 A2 to partial match against any entry in Sheet2 Column A and output Email into Sheet1 B2
I hope this makes sense.
Thanks
Anthony.
use this in B2:
=INDEX(Sheet2!B:B,AGGREGATE(15,6,ROW(Sheet2!$A$1:$A$2)/(ISNUMBER(SEARCH(A2,Sheet2!$A$1:$A$2))),1))

Updating Sheet2 as I enter new data on Sheet1

I have some data on Sheet1 from B2:G5480. I also have the same data on Sheet2 from B2:G5480 for separate calculations.
What I want is as I enter new rows on Sheet1 updating Sheet2 automatically.
Any help will be appreciate.
Method 1:
Make cells in sheet2 point to cells in sheet1
For example in Sheet2 cell A1 have formula =Sheet1!A1
Replicate this principle across the range B2:G5480, being sure not to overwrite formula cells
Method 2:
Make formulae in Sheet2 refer to data in Sheet1 by prefacing cell references with Sheet1! - leave all data on sheet1 in just one place.

Excel - Comparing Two columns to get a difference count

Scenario:
An Excel Workbook has 3 sheets. Sheet1 has an 'original' list of users WHICH DOES NOT CHANGE, Sheet2 has a list of 'current' users which does change, Sheet3 has some totalled information, like the total number of users on Sheet1 who are still on Sheet2.
Problem:
I can flag and count those on Sheet1 who are no longer on Sheet2, and provide a total count on Sheet3 - this uses another column on Sheet1 and an IF statement - but I can't do that for those on Sheet2 who are not on Sheet1 (someone was added, say) because the Sheet1 information is overwritten weekly by a manual process.
Question:
How do I show, on Sheet3 and from Sheet3, the total count of the number of users on Sheet2 who are not on Sheet1 when I can't add a column to Sheet2?
Many thanks in advance for your consideration of this problem - NigeH
Further Info:
Sheet1 ColumnA Rows 1-10 - Enter any 10 first names you want.
Sheet2 ColumnA Rows 1-10 - Enter 8 of the names from Sheet1 and 2 new ones.
Sheet3 - without using any new fields on Sheet1 or Sheet2 - and preferably only one field on Sheet3 - show the count of names on Sheet2 that aren't on Sheet1.
Try this array formula (assumes your lists are in column A in both sheets) ...
{=COUNTA(Sheet2!$A:$A)-SUM(IF(ISERROR(MATCH(Sheet2!$A:$A,Sheet1!$A:$A,0)),0,1))}
If you want to show the users that aren't on Sheet1 on Sheet3, fill down this formula ...
=IF(ISERROR(MATCH(Sheet2!$A1,Sheet1!$A:$A,0)),Sheet2!$A1,"")
I have a quick solution not so clever but works.
You will need 2 heaping columns. One column to get all users names from Sheet2
In Sheet3 in cell A1 you should write:
=Sheet2!A1
You should copy this in all cells from A1 to A(user name count);
Then in Sheet3 in cell B1 write:
=IF(ISBLANK(A1),"",VLOOKUP(Sheet2!A:A,Sheet1!A:A,1,FALSE))
You should copy this in all cells from B1 to B(user name count) NOT MORE;
And finally in Sheet3 in cell C1 you will have your count if you write:
=COUNTIF(B:B, NA())
If I get smarter way will edint.

Excel formula or Vba to Sum of all lookup value from multiple excelsheet

I need some help for the below scenario,
Sheet1 A2 has a date
Sheet2 and Sheet3 has dates in column A and numbers in column B
example as below,
I want to get the sum value from Sheet2 & Sheet3 B column for all the values in Sheet1 A2 if finds in Sheet2 & Sheet3 A.
Below is my formula which I can get the sum from Sheet2 but not able to do with both sheet2 and sheet3.
{=SUM((Sheet2!$B$2:$B$65500)*(Sheet2!$A$2:$A$65500='Sheet1'!A2))}
Please help in formula or vba, thanks
Can't you just add the two?
In B2 of sheet 1
=SUMIF(Sheet2!A:A,A2,Sheet2!B:B)+SUMIF(Sheet3!A:A,A2,Sheet3!B:B)

Resources