using vlookup for finding matching values - vba

I have value in A1 and another value in B1. I want to use a vlookup which checks if there is any value equal to A1 in Column A. And if These values match then B1 gets the value of the matching row of A.
As an example if A1 has a value Student and A6 has value Student. Then B1 should get the value of B6.
=VLOOKUP(
I know we use sth like this but i dont know how to fill the condition. Does anyone have any Suggestion?

=ADDRESS(MATCH(A1,C:C,0),3) where 3 is column C, you could use column(C1) here

What you are asking for cannot be done with a VLOOKUP. This is because if you are looking up a string in column A and using a reference from column A you will always return that string in column B, even if there is only one instance of that string. Unless that string did not exist in column A in the first place and then you would get an "#N/A".
The best way to solve your problem is to run a COUNTIF formula in column B, this will tell you how many instances of that string are found in column A.
Enter this into column B, and extend down:
=COUNTIF(A:A,A2)
Add a filter to column B, and filter out any 1's to give you a complete list of all your duplicates in column A.
The above formula assumes that you have headings in A1 & B1, and your data begins A2.

Related

Autofill multiple cells while filling one cell in Excel

The excel data looks like below:
Column A: Name
Column B: Role
Column C: Activity
Column D: Comments
Now in Columns A to C the entries are same and in Column D it is always different. Its like a timesheet of an employee.
So instead of filling Columns A to C the same, I want to put a formula such that when another entry in Column D is made, then Columns A to C are auto populated from the above filled data.
Please help.
You can create two tables using Format as Table:
If I understand you question right, you want to auto populate 2 different cells if a 3rd one is not empty.
Column A: Name
Column B: Role
Column C: Activity
Column D: Comments
Now in Columns A to C the entries are same and in Column D it is always different. Its like a timesheet of an employee.
Now in cells A to C add the following formula
=IF(NOT(ISBLANK(D1)),”Whatever you want in the cell”, “”)
What the function does is it looks if D1 cell is empty (you can also add ranges) and if it’s not; it adds “Whatever you want in the cell” to the cell holding the function; if cell D is empty, it leaves the holding cell empty
Alternatively, you can change the string to expression that fills your cell correctly

subtract the last two non-empty cell in excel

This is I think a simple problem but I can't seem to find the right solution for it. I don't know if VBA is needed for it. Basically I just want to subtract the last two non-empty cell in Excel. Example: I have the cell A1 and cell B1 and then subtract the value of A1 from B1 and place this value at the same row but another column C1 and so on. I have read this to get the last non-empty cell but I need two non-empty cell and perform operation on them.
=LOOKUP(2,1/(A:A<>""),A:A)
Is there an easier way to do this? Or should I use VBA?
EDIT:
the reason is I'm making a somewhat similar to a balance sheet but a simple one, the user will just enter deposited value at the first column and expenses at the second column and then display the balance in the third column.. and vice versa.
EDIT:
Sample
Put this in C4 and copy down:
=SUM($A$3:$A4)-SUM($B$3:$B4)
If you want to copy the formula past the data so it will automatically fill when data is inserted you can do what #Dirk stated:
=IF(A4&B4<>"",SUM(A$3:A4)-SUM(B$3:B4),"")
Put it in C4 and copy down as far as desired.
This way you can fill the column with the formula and as the data is filled it will change from the empty string to the running total.
EDIT:
Regular formula:
=IF(ROW($C1)=1,OFFSET($C1,0,-2)-OFFSET($C1,0,-1),OFFSET($C1,-1,0)+OFFSET($C1,0,-2)-OFFSET($C1,0,-1))
in cell C3 put "=A3-B3" in cell C4 put "=C3+A4-B4" then copy down.
This will start the balance at 3000 in C3 then add any deposits or minus any withdrawals to the rest of column C.

Creating a Dynamic Hyperlink in excel

I have three columns of data (columns A, B, and C).
Column A contains a number
Column B contains a name
Column C contains a URL
In cell E1, I have a drop down list that references the cells in column A.
I need a function that generates a hyperlink based on the number picked from the drop down menu using the cells that are adjacent in columns B and C. In otherwords, if E1 = any cell in column A, then create a hyperlink with the adjacent cells in columns B and C... more generally:
=IF(E1=[Any cell in column A],HYPERLINK([same row column C],[same row column B],"")
Is it possible to create a dynamic formula that will do this? I have found similar questions, but none that ask precisely this, and I cannot seem to piece together my searches to come up with a solution.
thanks to any who help.
enter image description here
I hope you looking for like this
formula:
=HYPERLINK(VLOOKUP(E1;A1:C5;3;0);VLOOKUP(E1;A1:C5;3;0))
I believe (if i'm mentally imagining your spreadsheet right) that you'd be better off using the VLookup function to retrieve the URL. If i'm wrong and it's reversed, the HLookup function may be what you need. They're similar, just depending on the pivot of whether you're aiming for a value in a row (Vlookup) or Column (Hlookup).
This article does a pretty good job of explaining HLookup:
https://support.office.com/en-us/article/VLOOKUP-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1
You can then use the lookup value for the HYPERLINK function to set the display text and the URL.

Check if one of multiple values is present in a column

I have a table in Excel 2013 that has has thousands of records of food items (Beef-frozen, beef-chilled, beef-brisket, beef-ribs, chicken-fillet, chicken-whole, fish-skinned, fish-whole, yogurt, lettuce-imported, lettuce-frozen, tomato-fresh,tomato, water, milk,...etc) stored in column A. Notice the value may contain other content than the food item name.
I created column B next to column A. I want column B to hold the category of the food item in column A. For example, if A1 has in it "Beef" or "Chicken" or "Fish" then B1 should equal "Meat". If A1 has in it "Tomato" or "Lettuce" or "Onion" then B1 should equal "Vegetable".
What is the best way to achieve it?
Assuming you have column headers, enter this formula in cell B2:
=REPT("Meat",MAX(IFERROR(MATCH({"*beef*","*chicken*","*fish*"},A2,),))) & REPT("Vegetable",MAX(IFERROR(MATCH({"*tomato*","*lettuce*","*onion*"},A2,),)))
This is an array formula and must be confirmed with Ctrl+Shift+Enter.
Now copy B2 and select B3 down as far as you need and paste.
Note: please look closely at the big gap in the middle of the formula. You'll see that this is really two separate formulas concatenated together with an ampersand. You can easily extend this formula in the same way by adding another phrase similar to the first two for a new category. In fact, you could add many more categories in this fashion.
Set up a two column table. Name it, for example FoodTable. Have the first column Named Word (for keyword) and the second column Type, for the type of product. Something like this:
Then, with your data in column A, enter the following formula in B1 and fill down:
=LOOKUP(2,1/ISNUMBER(FIND(FoodTable[Word],A1)),FoodTable[Type])
Results:

Searching and comparing various values using VBA

I have to create a macro which will:
Get the value from the cell A1 search this value in column C.
If the value in cell A1 exists in column C, the macro needs to be compare the value in cell B1 with values in column D.
If the value in cell A1 exists in column C AND the value in cell B1 exists in column D, then the text "Values found" should appear in cell E1.
The above needs to happen for all non empty rows in column A.
I was trying to use the following formula:
=IF(ISERROR(MATCH(A2,$C$2:$C$138,0)),"Load number not found","Load number found")
But it not working as I want. I have limited access to internet so I can't check all web sites. Would you please help me. Thanks a lot.
To check if A1 is in column C and if B1 is in column D (in the same row A1 was found in column C), then you need to do the following:
=IF(ISERROR(MATCH(A1,$C:$C,0)),"Load number not found",IF(B1=INDEX($D:$D,MATCH(A1,$C:$C,0),1),"Load number found","Load number not found"))
The first IF checks if A1 is in column C, the second IF checks if B1 is in column D (in the same row A1 was found in column C)
It will return "Load number found" only if both conditions are true. Otherwise it will return "Load number not found".
You can write a macro to do the same thing. But the easier way is to lock the cells in column E only and protect the sheet so that users will not accidentally change any of the formulas.
Update:
Since Column C can have duplicates, need to use the following array formula:
=IF(ISERROR(MATCH(1,(A1=$C:$C)*(B1=$D:$D),0)),"Load number not found","Load number found")
When you paste this formula to E1, make sure to press CTRL + Shift + Enter instead of just pressing the Enter key.
If I understand, a conventional solution with formulae is to concatenate your C and D column data and then search that. If you insert a new columnC with:
=D2&E2
copied down to suit you could apply (but say in ColumnF rather than ColumnE) your existing formula with only slight modification:
=IF(ISERROR(MATCH(A1&B1,$C$2:$C$138,0)),"Load number not found","Load number found")
subject to quite what is in which row.