Get price from table 1 if word is in the sentence tabel 2 (Excel, VBA, Vlookup, if, ? ,...) - vba

I try to get a price (col "B" sheet "PP") if a product (col "A" sheet "PP") is in any of sentence (col "A" sheet "MASTER"). If not, then it should pick up the average price (cell "C2" sheet "PP"). I've tried to use several methods but only this one gives SOME ;) results:
=IF((LEN(B2)-LEN(SUBSTITUTE(UPPER(B2);UPPER(LEFT(PP!A2;LEN(PP!A2)-5));"")))/LEN(LEFT(PP!A2;LEN(PP!A2)-5))>0;VLOOKUP(PP!A2;PP!$A$2:$J$82;2;0);PP!C2)
As you can see on a picture only a few products get results and it's not correct. I think it's because counting characters is different for different words and phrases. Maybe there are some other errors in this formula.
In Picture 1 you can see products with prices and its average from the sheet "PP".
In Picture 2 you can see sentences in which are products in red color - sheet "MASTER". There is one sentence - cell "B8", where are two products, and formula can pick up any of them, can be i.e the first one. Three last products on the mint background aren't in the list (sheet "PP"). Therefore for them, the formula should take an average price from cell "C2" sheet "PP".
The formula should make a loop because the products from sheet "PP" can be in a few sentences.
Can anybody help me to solve this issue?
SOLVED:
=IFERROR(LOOKUP(2^15;SEARCH(PP!$A$2:$A$11;B2);PP!$B$2:$B$11);PP!$C$2)

Related

Excel code to look for a specific text in a cell (from a list of possible texts) and populate another cell

So I am populating a spreadsheet with a copy n paste of my banking transactions. I want excel to populate a cell 10 to the left of it with that specific costs cost centre number.
Eg, Petrol has a cost centre number of 10
I copy and paste my bank statement in, the sheet sees all the cells containing 'petrol' and populates the cell ten to the left with a 10
I do not want to do this with a formula, I want to put it in vba.
Can someone help please?
Thanks in advance
You can use the following code to copy a value ten cells to the left.
Cells(Row,Column).Value = Cells(Row,Column + 10).Value
To get the values for 'Row' and 'Column', you can use the find function to find the address for 'petrol' and all the other values that you want.

Excel - Return Specific Values from Multiple Sheets

new to the forum and new to Excel in general. My buddies and I are creating a golf stats sheet and we wanted to see if there is a formula to pull specific data from specific values. Here is the example:
Sheet 1(Totals)
Sheet 2(Course 1)
Sheet 3(Course 2)
etc.
The Totals sheet will provide the list of players in Rows and in the first column will be Course names that can be selected as a List.
The other sheets (courses) will basically have score cards for that course. It'll inidicate names of who played that course along with course scores in a specific cell. i.e. Cell A1 would have the player name and B1 would have the total score.
What i would like is a formula in which, once a specific Course is selected in the Totals sheet, it'll return the specific player with its score.
So if i were to select Course 1 (Cell A1) in a drop down menu, the formula would look in the workbook and find the name Course 1 and return the player name is Cell B1 with the score in Cell C1.
I hope this didn't confuse anyone.
Assuming players are in A2 and down and the course name is in B1. Put this in B2 and drag.
=VLOOKUP(A2,INDIRECT("'"&B$1&"'!A:B"),2,FALSE)

Trying to Insert blank rows x number of times, x = cell value

I am trying to insert a specific number of blank rows, which is based on a value in a cell. This value in the cell is a count function from a table.
I have an "Import Table" sheet which contains all my data. Next to the table I have a couple count functions, which count general categories coming from the table. For example on the "Import Table" worksheet Cell J8(Domestic Equity), Cell J9 has the count function which for this case comes to "11". I now want 11 rows to be inserted at a specific spot in my "Analysis" worksheet. In this worksheet there are heading also names like the count headings(domestic equity).
So under domestic equity I want the rows to be insert. In the analysis sheet a function is already created in the first row under domestic equity, so the new blank rows have to be inserted under that value in this case under row 6.
The formula already existing in cells (A6,B6,C6,D6,E6) then have to be flash filled into the newly created white rows.
I attached 2 images to hopefully clear up my questions.
Thanks!
Range("A1").Resize(11, 1).Insert (xlShiftDown)
OR
Rows(1).Resize(11, 1).Insert (xlShiftDown)

Dynamic calculation in Excel based on a cell value

I've got a challenge in Excel i hope you guys can solve for me.
I have a drop down list (weeks) where i select the week 2015-18 to 2016-17. (nr 1 in picture)
In the cell called LY (nr 2 in picture) I want that to type the result of a dynamic sum range, based on the weeks input.
Picture of setup of the text above
The calculation logic is:
If i select week 2015-20, the VBA or formula should sum(F5:F7)/(G5:G7).
So in other words, I want a dynamic calculation that starts from week 2015-18 (F5/G5) and then sums the values down to the value that i have selected in "Weeks"
Picture of the setup of the logic values
The value of this calculation should be shown in LY (first picture, nr 2).
I really hope you can solve this for me. I've got more rows to calculate, so if you could come up with a "global" code that works for that, it would be great
ok, so you do not need VBA for this.....
for the sake of easier updates; mark the weekrange, right click them and give them a name, with Define name
I called it yearlyweeks
The two drop downs lists, will contain the value corresponding to the text indicating that week.
So we can use this to get a cells address by value (if that text is unique in the range named yearlyweeks):
=ADDRESS(MATCH(H8,yearlyweeks, 0), 2)
where H8 is the cell address of a dropdownlist cell. 2 is the column index of the "B" column
this will result in something like:
$B$2
where the 2 indicates the relative row index, in the range, not the absolute row number.
we are really not interested in the column, or relative row, only the absolute row, but so far we can live with relative..:
=ROW(INDIRECT(ADDRESS(MATCH(H8,yearlyweeks, 0), 2)))
this will give you the relative row of the cell coresponding to what you selected on the drop downlist for one of the lists. So I would do this in two calculation cells, just to avoid the next piece getting too long..
lets let the calculation cells be in I10, and J10..
I10 hold the relative row for the beginning week
J10 for the ending week
below create a new set of cells with:
="F"&(I10 + 7)
and
="G"&(J10 + 7)
where 7 is the row offset of yearlyweeks
in yet one more cell J12 we make the range string:
=CONCATENATE(I11;":";J11)
and then does the calculation in the final cell:
=SUM(INDIRECT(J12))
Now I can do this as a one liner, but you really would hate that

vlookup if name is matched display employee id

Ive never used vlookups i have a spreedsheet not sure if this is the right function. I have two sheets
Sheet 1
first name last name username
Sheet 2
first name last name employee id business unit
I need in column D on sheet 1 to have employee id ive below. Pay no attention to column letters and sheets because i moved to another sheet to try getting this right.
=MATCH(B11,Sheet1!C:C,0)
Any help is much appreciated.
So you realize you have to match both first and last names? There are several ways to accomplish this depending on how many employees you have in sheet 2: a) small list could a two-column search using array formula; b) large list just create another column in both sheets joining last & first names and do a MATCH or VLOOKUP on them.
Since your needs are simple and to illustrate option (b):
Insert a column in both Sheet1 and Sheet2 after the "last name"; you should now have an empty column C in both sheets.
Assuming you have column headers in row one, and thus data starts in row two, set cell C2 in both sheets with function =B2&","&A2, then fill-down that formula on both sheets in all rows.
Set Sheet1 cell E2 to formula =VLOOKUP(Sheet1!C2, Sheet2!$C:$D, 2, False), and fill-down that formula in all rows.
Voila, employee IDs on Sheet1. I do have to say this is so Excel 101. There are all sorts of examples and tutorials on this easily found using even the most trivial Google searches.