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
Related
I have 2 excel sheets (Sheet1 and Sheet2).
In sheet1 I have a table, I want to modify the table regarding to the second sheet as shown in the image such that the column in table of sheet1 (column called needed) looksup values in sheet2 and if id(1) is found in colmn of id in sheet2 then the cell of this id should get the value that corresponds to the same id in sheet 2.
That is what I basically want, but I can't figure out how to do that in excel
On Sheet1 in cell D2 enter the following formula:
=VLOOKUP(A2;Sheet2!$A$2:$D$5;4;FALSE)
Note that you might need to change the semicolons ; to regular commas , depending on your version of Excel. Then just copy that cell down the entire column of the table.
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.
I have spent the last week trying to find a solution to this. I'm a total novice in VBA and I need to match a name in column B of worksheet 1 with column A of worksheet 2 and then copy column C of worksheet 1 to the matched row in worksheet 2.
You can do this without VBA.
In worksheet 2 column C use the following formula
=VLOOKUP(A:A,Sheet1!B:C,2,false)
Replace Sheet1 with your sheet name.
I have two worksheets. One is Sheet1 and another is Sheet2.
In Sheet2, I want to use a formula to get the value from column N in Sheet 1.
I concatenate column A:B:C or A:B:D or A:B:E in Sheet1 and if any of this three conditions match X&Y&Z in sheet2, I get the value from column N in Sheet 1.
The formula below seems make sense to me but I get #Value! error.
=INDEX(SHEET1!$N$2:$N$100,MATCH(X2&Y2&Z2,OR((SHEET1!$A$2:$A$100&SHEET1!$B$2:$B$100&SHEET1!$C$2:$C$100),(SHEET1!$A$2:$A$100&SHEET1!$B$2:$B$100&SHEET1!$D$2:$D$100), (SHEET1!$A$2:$A$100&SHEET1!$B$2:$B$100&SHEET1!$E$2:$E$100)),0))
I suggest inserting a new ColumnA into Sheet1 populated from A2 down to suit with:
=B2&C2&D2&E2&F2
then in Sheet2 applying:
=INDEX(Sheet1!$O$2:$O$100,MATCH(X2&Y2&Z2,Sheet1!$A$2:$A$100,0))
This assumes your existing C, D and E columns in Sheet1 are blank if not containing the value you seek.
I have seen (searched) similar examples, but not quite what I am looking for.
I have a Workbook in Excel that has several sheets, Sheet A and B. These sheets have a bunch of data, so in order to display the most significant data on Sheet B from Sheet A, I want to mirror only the rows that I want to specify depending on the cell values on SheetA....I need to delete entire rows in Sheet B depending on the value in Sheet A.
For instance, in Sheet A I have column X with 10 values (Yes/No), and I have linked the same data with formulas back to Sheet B. That is, that if in SheetA X1="Yes", then SheetB cell Y1="Done"...if SheetA X2="Yes", then SheetB cell Y2="Done"...if SheetA X3="No", then SheetB cell Y1="Missing"..and so on.
So I only want the rows in SheetB with cell values="Done" to be there and thus want rows with cell values="Missing" to be automatically deleted. In this fashion, I would be creating a table that only includes the rows with "Done" values for the specified cell.
I know there are macros in Excel, but I have never written code in VBA, and the language handlers and variables escapes me entirely.
Is there a way to write a macro that can be called with in a formula; that is, e.x) if(A10="Yes", "", delete row macro here)???
Thanks!
From the wording in your question it seems you want to create a function that can be used in a cell that will alter other cells. That cannot be done. The functions, when used in a formula, are limited to changing the cell itself, and not other cells.
More then one way to skin a cat. Like Abe said you can`t use formula to alter other cells. But you can use VBA. The below sub removes entire rows where the cell in range is equal to 1. But you can make it equal to whatever you want.
Sub DeleteRows()
Dim FoundCell As Range
Set FoundCell = Worksheets("SheetB").Range("YourRange").Find(what:=1)
Do Until FoundCell Is Nothing
FoundCell.EntireRow.Delete
Set FoundCell = Worksheets("SheetB").Range("YourRange").FindNext
Loop
End Sub
Of course this is extra work. What you should do instead of copying the data from A to B and then processing it, just copy the done cells from A to B.