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

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.

Related

Which sheet contains the duplicate?

In excel, I have multiple sheets each with a column of numbers. I have it set up to highlight any cell that is a duplicate of a value on any sheet in the same column.
Also, how to have the sheet name(s) displayed in a cell to the left of the duplicate values?
For example; if I have sheetA, sheetB, and sheetC, each with a Number column, if I enter a value on sheetC that already exists on sheetA both cells will be highlighted. I would also like on sheetC the cell next to the duplicate value to change to "sheetA" indicating that the duplicate value is on sheetA.
I haven't been able to find any information that would even being to point me in the right direction.
Formula for in which sheet number is found:
=TEXTJOIN(", ";TRUE;IF(COUNTIF(shee1!$A$1:$A$30;Sheet3!A1)>0;"Sheet1";"");IF(COUNTIF(Sheet2!$A$1:$A$30;Sheet3!A1)>0;"Sheet2";""))
Formula for conditonal formatting (for sheet 3, do similar with other sheets):
=ISNUMBER(MATCH(A1;VSTACK(shee1!$A$1:$A$30;Sheet2!$A$1:$A$30);0))

VBA Copy and paste values in one cell based on value in another cell

in this picture, the data in column I and R are both formulas. I want to write a code to have the formula in column I paste AS VALUES if there is an asterisk in the same row of column R and do nothin if it is blank. I need to do this for rows 9:44.

Excel - how to match a column header with a row header (dates) and return a lookup value in VBA

I've looked high and low for this and can't find a solution. Plenty with formulas, but it must be in VBA.
I have a range of text in column A (A2:A100) and dates in column B (B2:B100), with sequential calendar dates in row 1 (C1:Z1). For every cell in the matrix/table, if the date in column B is the same as the date in row 1, the text in corresponding column A must be displayed. I can't use a VLOOKUP or MATCH formula, as the columns are narrow and don't display the full text unwrapped because of the formula in the adjacent cell. Thanks for any guidance. In the below, N2 must be "Electrician chasing", since N1 is the same as B2.
I think you want this (and you got your columns A and B the wrong way round)
Sub LoopAndDisplay
Dim r as range
For each r in range("C2:Z200")
If cells(1,r.column) = cells(r.row,2) then 'if date above matches column B then
r = cells(r.row,1) 'display contents of column A
End If
Next R
End Sub

Match 2 colums in 2 excel sheets and paste a third

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.

Match concatenated columns from this worksheet to another worksheet with multiple conditions

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.

Resources