Excel VBA matching record copy data between worksheets - excel

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.

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

How to find combination of multiple cells in a range in excel

How can I find all of multiple cell values of an excel workbook in a column of other workbook?
Example:I have 2 workbooks workbook 1 and workbook 2
in Workbook 1 I need a formula in D1 which finds all the words of the first row in workbook 2 range A:A and returns the value of second column of workbook 2.
For instance, In D1 the formula needs to return 1423.00, though there is an extra word in A1 - "boy".
try this per the sample image,
=INDEX(G:G, AGGREGATE(15, 7, ROW(A:A)/(ISNUMBER(SEARCH(A2, F$1:F$5))*ISNUMBER(SEARCH(B2, F$1:F$5))*ISNUMBER(SEARCH(C2, F$1:F$5))), 1))
As per your sample given
workbook 1 name is Book17 and workbook 2 name is Book19 in below formula. Apply the below formula in Book17 in D2
=TEXT(IF(ISERROR(FIND(A2&" "&B2&" "&C2,[Book19]Sheet1!A2)),"Not Match",INDEX([Book19]Sheet1!A2:B2,1,2)),".00")
As per your sample given
workbook 1 name is Book17 and workbook 2 name is Book19 in below formula. Apply the below formula in Book17 in D2
=TEXT(IF(ISERROR(FIND(A2&" "&B2&" "&C2,[Book19]Sheet1!A2)),"Not Match",INDEX([Book19]Sheet1!A2:B2,1,2)),".00")
workbook 1:
Workbook 2:

VBA Macro - Copy Partial Row from Sheet to New Sheet if Cell Matches Cell on 3rd Sheet

So I don't know much about coding but I’m learn quick and have made things work in the past by piggybacking off of existing code the others created, but there are too many moving parts with this one for me.
I need some help writing a VBA for an excel spreadsheet that will save me significant amounts of time comparing & aggregating data going forward. The alternative would be to create multiple VLookup & If commands in the worksheets, which you all know leads to instability in the worksheet.
Any help would be greatly appreciated.
Here's the spreadsheet layout:
Worksheet 1 = "3yr"
Worksheet 2 = "5yr"
Worksheet 3 = "10yr"
Worksheet 4 = "15yr"
Worksheet 5 = "Combined"
Worksheet 6 = "Eligible Funds"
Row 1 is the same in all worksheets
Cell A2 is a counter cell using =COUNTA(A3:A1048576)
There shouldn’t be a break between any of the rows
Not sure if this is needed, as I’ve seen code that does this in the macro (if that’s the case I will delete that row)
Row 2 in Worksheets 1-5 are identical; Cells A2:BF2 are the column headers
Worksheet 5 has 5 additional columns from BG:BL
Worksheet 6 contains the data that Worksheets 1-4 are going to be cross-referenced against
Worksheet 5 is going to be the target worksheet to copy the data to, beginning on row 3, if there is a match
Here's what I'm trying to do:
Search Column F of Worksheet 6, row-by-row for “WMC Ineligible” or “Ineligible Share Class” and then delete that entire row if either of those texts are found
Search Column A of Worksheet 6 for a match of the text in Column B of Worksheet 1 (starts at row 3), row-by-row
If found, then search the Column B of Worksheet 5 to see if that row already exists
If that row doesn’t exist, copy the cells in columns A2:BF2 for that row (from Worksheet 1) to the first blank row in Worksheet 5, input “1” in column BG, “=SUM(BG3:BJ3)” in column BK, and then copy the text in Column D of the row found in Worksheet 6 into Column BL of the new row in Worksheet 5
For worksheet 2 it would input “1” in column BH, “=SUM(BG3:BJ3)” in column BK, and then copy the text in Column D of the row found in Worksheet 6 into Column BL of the new row in Worksheet 5
For worksheet 3 it would input “1” in column BI “=SUM(BG3:BJ3)” in column BK, and then copy the text in Column D of the row found in Worksheet 6 into Column BL of the new row in Worksheet 5
For worksheet 4 it would input “1” in column BJ “=SUM(BG3:BJ3)” in column BK, and then copy the text in Column D of the row found in Worksheet 6 into Column BL of the new row in Worksheet 5
If that row exists, then don’t copy the row again, but instead input:
“1” in column BH of that row (if searching Worksheet 2)
“1” in column BI of that row (if searching Worksheet 3)
“1” in column BJ of that row (if searching Worksheet 4)
Move to the next row in Worksheet 1 and repeat the search
Once the end of Worksheet 1 is reached, move on to Worksheet 2, then Worksheet 3, and finally worksheet 4
Again, any help would be greatly appreciated.

Copying rows from a worksheet to 4 different worksheets

Please suggest how to copy rows of data from one worksheet to 4 different worksheets for
a. Previous month
b. Current year YTD
c. Previous year month
d. Previous year YTD
You can access any cell of any worksheet using
Sheet("Sheetname").Cells(rownumber, columnnumber) if you know the name of the worksheets or Sheet(index).Cells(rownumber,columnumber) if only the index of the worksheets are fixed.
To copy the value you can just write Sheet(index1).Cells(rownumber1, columnnumber1)=Sheet(index2).Cells(rownumber2, columnnumber2)
You can select a whole row as well by Rows(index).Select or multiple rows by Rows("startIndex:endIndex").Select

VLOOKUP in 2 sheets of an excel

I have a column in Sheet 1 of an excel which I want to compare with an column of Sheet 2 of the same excel.
The values of Sheet 1 column to be present in some rows of Sheet 2 column (not necessary to be row by row).
How to use VLOOKUP here ?
Something like:
=IF(ISNA(MATCH(A1,Sheet2!B:B,0)),"no match","match")

Resources