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

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.

Related

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

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)

Index, Match and Address functions in a formula but how do incorporate a certain condition to extract only certain data?

My Workbook has three sheets: "Wire Sheet", "Paste Data" sheet and "Wire instructions"
I need the "Wire sheet to dynamically populate with the data from the other two sheets based on certain conditions, i.e. date and data from that date.
I am using the index, match address functions to find the names from the "paste data" tab based on a specific but I can't figure out how to put a condition in there to only return names that are "buys"...
Here are my formulas:
This is just to find the cell:
S17= =MAX(IF('Paste Data'!B:B = 'Wire Sheet'!K2, ROW('Paste Data'!B:B) - ROW(INDEX('Paste Data'!B:B,1,1))+1))
S18= =ADDRESS(MATCH(K2,'Paste Data'!B:B,0),2,3,1,"Paste Data")&":"&ADDRESS(S17,5,3,1)
S19= =INDEX(S18,1)
here is the formula i am using to return the data:
=IF(INDEX(INDIRECT(S19),1,4)=0,"",INDEX(INDIRECT(S19),1,4))
Example on how spreadsheet works:
Currently: if you place a specific date in cell K2 on the "wire sheet", the boxes (cells A18:O67) populate with the data from the other two sheets based on that specific date. The data coded "Sell" is being populated in the boxes on the wire sheet, but should not be.. here is an example:
For example: If you place the date 7/13/2018 in K2 cell, the cell B57 is populated with letters SCR, which shouldn't be the case, as if you go to the "paste data" sheet, this is a "sell".
enter image description here
Then if you place the date 7/16/2018 in K2 Cell -- the cell B18 is doing the same thing, its populated with WQ when it shouldn't be, as it is a "sell", on the "paste Data" sheet. I would like it to just skip over this row of data and go and find the next row that is coded "buy"..
enter image description here
I just want to place the data that are "buys", on the wire sheet. All the sells should be passed over. I am not sure how else to explain this, which might be part of the issue.
enter image description here
Thanks in advance.
https://my.pcloud.com/publink/show?code=XZNzcB7ZpIigcTAabUz2vpPaXQ4nSVUfdc2X
+-----[editRevision2]----+
My way :
Y5 =COUNTIF('Paste Data'!B:B,'Wire Sheet'!K2)
Z6 =IF((ROW(Z6)-5)<=Y$5,ROW(Z6)-5,"")
AA6 =INDEX('Paste Data'!F:F,MATCH('Wire Sheet'!$K$2,'Paste Data'!B:B,0)+'Wire Sheet'!Z6-1,1)
AB6 =IF(AA6="Buy",AB5+1,AB5)
AC6 =IF(AA6="Buy",INDEX('Paste Data'!E:E,MATCH('Wire Sheet'!$K$2,'Paste Data'!B:B,0)+'Wire Sheet'!Z6-1),"")
AD6 =IF(AA6="Buy",INDEX('Paste Data'!K:K,MATCH('Wire Sheet'!$K$2,'Paste Data'!B:B,0)+'Wire Sheet'!Z6-1),"")
select Z6:AD6 and extend to D15, then
B18 =IFERROR(INDEX($AC:$AC,MATCH(A18,$AB:$AB,0)),"")
E19 =IFERROR(INDEX($AD:$AD,MATCH(A18,$AB:$AB,0)),"")
copy B18 to J18, B31, J31 ...
and copy E20 to J20, B33, J33 ...
+-----[ProviousEdit]----+
Make
B18 =if(SUMIFS('Paste Data'!$K:$K,'Paste Data'!$E:$E,IF(INDEX(INDIRECT(S19),1,4)=0,"",INDEX(INDIRECT(S19),1,4)),'Paste Data'!$B:$B,$K$2,'Paste Data'!$F:$F,"Buy")=0,"",IF(INDEX(INDIRECT(S19),1,4)=0,"",INDEX(INDIRECT(S19),1,4)))
and adjust the INDEX(INDIRECT(S19),1,4) accordingly for J18,B31,J31 ...
Hope that solves.. (:

Excel VBA checks cells in certain order before returning a value from one of them in another cell

I have a row of 4 cells that contain either 3 0's and a number, or two numbers and 2 0's. I need excel to check the cells from left to right and if a cell contains a 0 move on to the next cell until it finds a number and then return that number in cell 5. Any help would be grately appreciated!!
My test Data
enter image description here
Enter this formula in Column E,
=IF(A1=0,IF(B1=0,IF(C1=0,IF(D1=0,"All are Zeroes",D1),C1),B1),A1)
Use this formula:
=INDEX($A1:$D1,AGGREGATE(15,6,COLUMN($A1:$D1)/($A1:$D1<>0),1))

Shift Cells left whle filtering in ms excel 2007

I have a table and i filtered data based on one specific criteria and i want to shift cells left after deleting one selected column data.
Please help.
hey simply use = sign in require left cell and put column position which you want to put e.g if you have data in B1 cell & u want to put the data in A1(left) then simply write =B1 in A1 cell
and drag down upto where you want the data

Input formula into cell using xlR1C1 style

I have a formula to implement in xlR1C1 style.
I add a new marketing entry into my marketing database. I want Cells (emptyRowM,9) to search a marketing referral code in Cells (emptyRowM, 7) in the pivot table of another sheet. This pivot table shows the total revenue associated to each marketing referral code. Hence if Cells (emptyRowM, 7) is zero, Cells (emptyRowM, 9 will be blank, otherwise, it will sum up all the revenue associated with the referral code.
Dim emptyRowM As Long
emptyRowM = Range("B100000").End(xlUp).Offset(1, 0).Row
Cells (emptyRowM, 9) = "=IF(AND(SUMIF('Pivot Table'!B6:B99,'Marketing Data'!G12,'Pivot Table'!C6:C99)=0),"",SUMIF('Pivot Table'!B6:B99,'Marketing Data'!G12,'Pivot Table'!C6:C99))"
Go File-> Options -> Formulas there under working with Formula tick "R1C1 reference style"
So your formula should become something like
=IF(AND(SUMIF('Pivot Table'!R[-5]C[-5]:R[88]C[-5],'Marketing Data'!R[1]C,'Pivot Table'!R[-5]C[-4]:R[88]C[-4])=0),"",SUMIF('Pivot Table'!R[-5]C[-5]:R[88]C[-5],'Marketing Data'!
Then use the Cells (emptyRowM, 9).FormulaR1C1="=IF(AND(SUMIF('Pivot Table'!R[-5]C[-5]:R[88]C[-5],'Marketing Data'!R[1]C,'Pivot Table'!R[-5]C[-4]:R[88]C[-4])=0),"",SUMIF('Pivot Table'!R[-5]C[-5]:R[88]C[-5],'Marketing Data'!"
Let me know if you have any problems.
Cheers,
Sujoy