Match 2 colums in 2 excel sheets and paste a third - excel

I have two excel sheets both with matching product numbers. What I need to do is match the product numbers and then copy a column from the first sheet to the second.
My example:
Column C in the first sheet contains product numbers
Column A in the second sheet contains product numbers
I want to match C & A and then copy column B from the first to the second sheet.
Sorry if this has been answered before, my knowledge is basic but I am trying to learn
Thanks for any help.
CD

Assuming your numbers to match start in C2 (headers in row 1) and numbers to copy in AC2 on Sheet1, this should do what you want. Paste it into AC2 on Sheet2 and then drag copy to the length of column A on Sheet2.
=IF(IFNA(MATCH(A2,Sheet1!C:C,0), FALSE), INDIRECT("Sheet1!AC"&MATCH(A2, Sheet1!C:C, 0)), "Not Found")
Note this will give "Not Found" for a value on Sheet2 which is not found on Sheet1, you can change that by just replacing the string "Not Found" in the formula with whatever you want (e.g. 0).

Formula:
You can use OFFSET with IF. In B1 of sheet 2 for example you could put, drag down for as many rows as required,
=IF(A1=Sheet1!C1,OFFSET(Sheet1!A1,0,COLUMNS(Sheet1!A:AC)-1,1,1))
If you set your data up as a table in sheet 2 (Ctrl + T with an populated cell selected) then add this formula to the appropriate column it will autofilter down the formula.
Or:
With code in a standard module:
Public Sub AddFormula()
Dim rng As Range
With Worksheets("Sheet2")
If Application.WorksheetFunction.Subtotal(103, .Columns(1).Cells) > 0 Then
For Each rng In Intersect(.Columns(1), .UsedRange)
If Not IsEmpty(rng) And Not IsError(rng) Then 'assume ignore empty cells
If rng = Worksheets("Sheet1").Cells(rng.Row, "C") Then Worksheets("Sheet1").Cells(rng.Row, "AC").Copy rng.Offset(, 1) 'determine where you want value to go
End If
Next rng
End If
End With
End Sub
Note:
This is based on your comment that you are comparing sheet2 col A with sheet1 col C and copying sheet1 col AC if match.

I assume that the product numbers in both sheets are unique. If that, I suggest use the offset and match formulas to achieve what you want.
sorry for my half-baked answer due to i just typed them with phone and it is not convenient to input complicated style, here is the additional information:
the match formula is used to query the location of the target product number in the original sheet( sheet 1 in your case above);
after we located the position of the target product number, extract the information you wanted through the offset formula.
here are the specific process:
Sheet 1 represent the original information and sheet 2 represent the target one. What we required to do is copy the info in col D of sheet 1 to col D of sheet through the product:
OFFSET($D$5,MATCH(I6,$D$5:$D$16,0)-1,1,1,1)
OFFSET($D$5,MATCH(I7,$D$5:$D$16,0)-1,1,1,1)
OFFSET($D$5,MATCH(I8,$D$5:$D$16,0)-1,1,1,1)
OFFSET($D$5,MATCH(I9,$D$5:$D$16,0)-1,1,1,1)
OFFSET($D$5,MATCH(I10,$D$5:$D$16,0)-1,1,1,1)
or you can refer to the output directly:
enter image description here
for more information about these two formulas, you can refer to the help of excel of google.

Related

Best formula to use for summing multiple column returns 1 row down from search value

I need to copy over data from one worksheet to a master worksheet. I do this with a new created worksheet every week. The new worksheets I create every week use the same cell layout so I would need to use a formula that I can copy and paste on the master worksheet.
The values I need to return and sum are 1 row below the lookup_value that I would normally use in Vlookup; they are also 8 columns across.
lookup_value is in cell A138, Values to return and sum are in cells H139:P139.
These are the same cells every worksheet.
I've tried to use variances of Sum(Vlookup($H$139:$P$139,{8,9,10,11,12,13,14,15,16} & Index(Match but continue to get #REF! or #Value!
what formula structure can I use to lookup_value and return 1 row below and sum columns H - P?
Image 1 of "Master Worksheet" formula is located in cell I1996 under "Qty in Transit" This row is in reference to Part # A03781402 shown on the right.
Image 2 of "Worksheet 1" You can see where Part # A03781402 is referenced in cell A138. Now I just need to grab the Qty from Cells H139:P139, sum & return to "Master Worksheet" Cell I1996
Formula for 'Master Worksheet'!I1996 to sum 'Worksheet 1'!H:P one row below the row that matches 'Master Worksheet'!R1996 in 'Worksheet 1'!A:A.
=sum(index('Worksheet 1'!H:P, match(R1996, 'Worksheet 1'!A:A, 0)+1, 0))
The 0 as the column_num in INDEX is important; it means all columns within the indexed range.
You need to use something like a SUMIF:
=SUMIF($H$138:$P$138,$A$138,$H$139:$P$139)
If the lookup_value is in Z1 and the lookup_array ColumnA, then please try:
=SUM(INDEX(H:P,1+MATCH(Z1,A:A,0),))

Excel fetch rows based on a cell value in another sheet

sorry for being a total noob in excel!
I have two sheets, sheet 1 named "Stocks" and sheet 2 named "Stocks search".
In "Stocks" I have from A1 to B700 values. In A column I have the stocks symbols and in B column I have the stocks' issuers symbols, so every entry in A column is unique, yet there can be repeating entries in column B.
So in sheet "Stocks search", if I enter in A1 an issuer's symbol, I want for the formula to go search in sheet "Stocks" and fetch all stocks that this issuer has in new rows.
How can this be done in a formula? Thanks in advance!
This is a VBA solution to the question. IMHO, this is more appropriate than a formula (in this case). The formula approach is OK, but there are drawbacks - you have to remember the CSE rule, and then copy the formulas down the right number of rows (which you don't know in advance), etc, etc.
This code uses the same assumptions as the formula approach.
1 - sheets = Stocks and Stock report
2 - Data in Sheets, columns A and B (header in row 1)
3 - lookup code is on Stock report
4 - Output is on Stock report
One of the advantages is that if new data is added to the Stocks sheet (i.e. the bottom row > 700), the vba automatically adjusts.
The code is self-documented. But the essence is that it creates an autofilter on "Stocks" using the lookup value as the criterion; copies the rows that meet the criteria; and pastes the result to an output range on "Stock reports". The output range is cleared before the copy/paste takes place so that there are no left-overs from any previous lookup.
I think there's something to be said for creating a dropdown list for the lookup cell. No doubt that could be automated too by getting the codes from Column A, getting the unique values, and then apply them to the lookup cell. Just a thought;)
Sub so_52537740()
' CREDITS
'
' Refer: https://stackoverflow.com/questions/17531128/copy-paste-calculate-visible-cells-from-one-column-of-a-filtered-table
' Date: 8 July 2013
' Submitted by: Jon Crowell (https://stackoverflow.com/users/138938/jon-crowell)
Dim src As Worksheet, tgt As Worksheet
Dim filterRange As Range, copyRange As Range
Dim lastRow As Long
Dim stocks As String, stockreport As String
' set values for sheet names
stocks = "Stocks"
stockreport = "Stock report"
' set values for Sheet variables
Set src = ThisWorkbook.Sheets(stocks)
Set tgt = ThisWorkbook.Sheets(stockreport)
' clear the exist target data
tgt.Range("A4:B" & Rows.Count).ClearContents
' turn off any autofilters that are already set
If src.AutoFilterMode Then src.AutoFilter.ShowAllData
' find the last row in the Stocks sheet with data in column A
lastRow = src.Range("A" & src.Rows.Count).End(xlUp).Row
' the range that we are auto-filtering (all columns)
Set filterRange = src.Range("A1:B" & lastRow)
' the range we want to copy (only columns we want to copy)
' in this case we are copying both columns A and B
' we set the range to start in row 2 to prevent copying the header
Set copyRange = src.Range("A2:B" & lastRow)
' filter range based on column A being equal the the value in Cell A1 of the stockreport
' consider making this a dropdown list so that there are no errors
filterRange.AutoFilter field:=1, Criteria1:=Format(Sheets(stockreport).Range("a1").Value)
' copy the visible cells to our target range
' note that you can easily find the last populated row on this sheet
' if you don't want to over-write your previous results
copyRange.SpecialCells(xlCellTypeVisible).copy tgt.Range("A4")
' turn off any autofilters that are already set
If src.AutoFilterMode Then src.AutoFilter.ShowAllData
End Sub
Giving due credit: There is, as they say, nothing new under the sun. I have based this answer on an excellent piece of work by Jon Crowell on a question in StackOverflow "Copy/Paste/Calculate Visible Cells from One Column of a Filtered Table" in July 2013. Just goes to show what a bit of Googling and perseverance can achieve.
I believe I have an answer for you.
Try
=IFERROR(INDEX('Stocks Search'!$A$1:$A$700,SMALL(IF('Stocks Search'!$B$1:$B$700=$A$1,ROW('Stocks Search'!$A$1:$A$700)-MIN(ROW('Stocks Search'!$A$1:$A$700))+1),COLUMNS($A$1:A1))),"")
This is a CSE formula. What that means is once you enter it into cell B1, you will need to press Control+Shift+Enter. Once you do this, these brackets will appear around your formula {}
Click the fill button in the bottom right of the cell and drag the formula to the right (you will need to do this for as many cells as it is possible for answers). So if Company A has 40 possible answers, you will need to have this formula go at least 40 cells to the right.
The application of CSE formulas can be tricky. Essentially you need to go to the end of the formula in the formula bar, and then use Control+Shift+Enter.
I hope this helps.

Troubleshooting Excel- compare cell to range them copy text in next column

I have two sheets. One has a column of text. The other has a column of text and an adjacent column with a number.
I want to compare each cell to the range on another sheet. If the text on sheet B is found I want to pull the number next to the column in sheet A and put it next to column next to the string on sheet B.
This seems to work for the first cell, but when I copy/paste it returns 0.
=IF(COUNTIF(D2,'ClientKW Input'!$B$1:$B$337),'ClientKW Input'!$A$1:$A$337,0)
For column D2 it returns the correct number but not for d3 and other cells?!?
You could also use INDEX MATCH to achieve this. Something like the following:
=INDEX(Sheet1!B:B, MATCH(Sheet2!A1, Sheet1!A:A, 0))
In the above example, the data you are pulling is in Sheet 1 col B, the value you are using to search is Sheet 2 col A, matching up with Sheet 1 col A. You might have to change this for you specific needs.

Aggregate words ending with a set of patterns into a new sheet

I have Excel 2010 and I am trying to consolidate a list of words.
Sheet1 contains a column with a list of words such as 'ing', 'ed', 'en'....
Sheet2 contains a column with words such as 'Flying', 'Opening', 'Taken', 'Baked', 'Awaken' etc.
Sheet3, for every column value in Sheet1, I want a function that compares the word with all the words from Sheet2 and collects them together in sheet3.
So, Sheet3 should have 3 columns after running this
first column should have 'Flying', 'Opening' - all words ending with 'ing'
second column should have 'Baked' - all words ending with 'ed'
third column should have 'Taken', "Awaken' - all words ending with 'en'
I tried using the formula below for one of the words and it seems to work for one word at a time but I am not sure how to automate this - do I need to use a macro for this ?
=IF(RIGHT(A1:A7, 3)="ing", A1:A7, "")
Can anyone please suggest how to approach this ?
Regards,
Sonu
Ignore my request for clarification - I have re-read and now understand your question.
The following code will work for what you describe. It assumes the following:
The list of word endings in Sheet1 and the list of words in sheet2
are both contiguous lists starting from cell A1 and extending
downwards.
Cell A1 in Sheet2 contains a column heading, e.g. "My Words" which will not be copied to the columns of words in Sheet3. If you want the heading copied, remove .Offset(1,0) from line 13.
There are no more entries in the list on Sheet1 than there are columns available to you in your version of Excel (e.g. XL2003=256)
Sheet3 is empty prior to the macro starting
You have not changed the default VBA codenames of the 3 worksheet
objects
The sheets are not protected
.
Sub extract()
Dim rFilt As Range
Dim rSrc As Range
Dim iTgtCol As Integer
If Sheet2.FilterMode Then Sheet2.ShowAllData
If Not Sheet2.AutoFilterMode Then Sheet2.Cells(1).CurrentRegion.AutoFilter
Set rSrc = Sheet2.Cells(1).CurrentRegion.Columns(1)
iTgtCol = 0
For Each rFilt In Sheet1.Cells(1).CurrentRegion.Columns(1).Cells
iTgtCol = iTgtCol + 1
With rSrc
.AutoFilter field:=1, Criteria1:="=*" & rFilt
.Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Sheet3.Cells(iTgtCol)
End With
Next rFilt
Sheet2.ShowAllData
End Sub

Excel 2007 - Formula changes to #REF

So I've got this Workbook which contains a lot of data. And I've got this one sheet which basically copies the data based on certain conditions.
Each cell in each row looks like this (the last specified cell is the one where the formula is in):
=IF(Numbers1!E2<>0;Numbers1!A2;"")
=IF(Numbers1!E3<>0;Numbers1!A3;"")
=IF(Numbers1!E4<>0;Numbers1!A4;"")
=IF(Numbers1!E2<>0;Numbers1!B2;"")
=IF(Numbers1!E3<>0;Numbers1!B3;"")
=IF(Numbers1!E4<>0;Numbers1!B4;"")
So the formula in cell A2 is the first one, formula in A3 is the second line etc.
I want to copy the value from the same column and row from the sheet Numbers1, IF the value in the same row of column E is not 0. This seems to be working just fine.
But, when I update the data in Numbers1 sheet, the formulas are all of a sudden invalid and the formula now looks like this:
=IF(Numbers1!#REF!<>0;Numbers1!#REF!;"")
Each formula in each cells look identical to the formula above. And I can't have that, why can't Excel just keep the formula as it is without "helping" me?
Since you may be better off using a macro to rewrite your formulas, here are the basics:
Sub RewriteFormulas()
Dim row, col As Integer
row = 1 'row you want your target formulas to be on
For row = 1 To 60
For col = 1 To 13
ActiveSheet.Cells(row, col).Formula = "=IF(Numbers1!" & Cells(row,col).Address & "<>0,Numbers1!" & Cells(row+2,col).Adddress & ","""")"
Next row
Next col
End Sub
You can play around with using different sheets (or different workbooks) instead of just ActiveSheet so you can have 1 workbook that stores the macro and alters data in whatever workbooks provide your updated datasets.
Hope that helps...

Resources