VBA if value in cell display string in other cell - excel

I'm trying to set some things in my Excel in order to improve my process.
I would like to create a VBA function which let to display value in cell B13 if cell B11 contains "_01_Clients_Particuliers" and cell B12 contains "_00".
These cells are dropdown list.
I never use VBA up to now.
I could write into the cell B13 :
=IF(COUNTIF(B11,"_01_Clients_Particuliers"),"_100PRD05","")
But I need to take into account two cells and I assume I need to use VBA to do that, because the cell B14 has already a formula : =INDIRECT(B13)
Do you have any idea ?

Assuming you drop-down list only contain few selection, then the following formula should be work for you.
=IF(AND(ISNUMBER(SEARCH(H1,C1)),ISNUMBER(SEARCH(H2,C2))),"It is there","not found")
In addition, you will write the range reference directly, it will return error in my case

Unless I've misunderstood your question, I don't think you need VBA to do this.
Check out Using IF with AND, OR and NOT functions
Again, apologies if I'm mistaken, but it seems that your desired result could be produced with the following formula in B13:
IF(AND(B11 = "_01_Clients_Particuliers", B12 = "_00"), "_100PRD05","")
This will put the value "_100PRD05" in B13 if B11 equals "_01_Clients_Particuliers" and B12 equals "_00".

Related

Excel function reference specific cell and all cells below

I am trying to write a function in excel that references a range from specific cell in a column, in this example A22 or B22 to the last cell in that column. Something like this:
=MAX(IF('Sheet1'!$A$22:$A$LAST="YES",'Sheet1'!$B$22:$B$LAST))
How do I accomplish this?
Or........
=LOOKUP(1,0/(A:A="YES"),B:B)
Replace the end reference with INDEX MATCH
=MAX(IF('Sheet1'!$A$22:INDEX('Sheet1'!$A:$A,MATCH(1E+99,'Sheet1'!$B:$B))="YES",'Sheet1'!$B$22:INDEX('Sheet1'!$B:$B,MATCH(1E+99,'Sheet1'!$B:$B))))
Remember to confirm with Ctrl-Shift-Enter.

Get Excel cell relative reference into a cell

I am trying to find how to get an excel formula to get a cell's relative reference into a cell.
A formula that would be like =getcellreference(B2) and then has B2 as the output.
Nothing complicated but i could not find a simple solution.
You can use CELL():
=CELL("address",B2)
For formatting to literally show B2 instead of the absolute reference, you can do:
=SUBSTITUTE(CELL("address",B2),"$","")
If all you are trying to do is output a cell reference that you manually input, then all you need to do is:
="B2"
or
B2 (no equals sign)
You can use the ADDRESS function to obtain the address of a cell in a worksheet, given specified row and column numbers
ADDRESS(row_num, column_num, [abs_num], [a1], [sheet_text])
So for cell B2, you will need to put =ADDRESS(2,2) where the first 2 stands for the row number and 2nd is for column B.

I am trying to use a cell text string as a cell reference

I would like to use the text contents of cell A1 , to change the cell references of a formula in A2.
That is, I want inputs to A1 (e.g. the number "4") to change the formula in A2 (which starts off as =SUM(B1:B4) to =SUM(B1:B8).
In sum, I would like the cell references in the formula of A2 to change according to the value in A1.
How can this be done?
In Excel, if you use the INDIRECT function, you can refer to another cell's value by using text provided to the function, so:-
=INDIRECT("B"&A4)
If A4 contained the value "2", then the function would refer to B2.
Hope that makes sense. Using this you can then hopefully get your formula to behave the way you want.
For more info try this
So, if the value you stick in A1 is something like "4" and then you want to change that to "8" and have it affect the range inside the first Sum (for instance) you could use =Indirect():
=SUM(Indirect("B1:B" & A1))

Comparing cells with using Excel LEFT Function

I wanted to compare value in cell A1 and B1.
However, sometimes PC give different value as cell B1.
Initial code I've been writing is as below in cell C1:
=IF(ISERROR(MATCH(A1,$B$1:$B$5,0)),"","Duplicate")
This code only compare exact value. Thus, I'm trying to add LEFT Function into function above:
=IF(ISERROR(MATCH(Left(A1,8),$B$1:$B$5,0)),"","Duplicate")
But above function only count character in A1 only. How do I add LEFT(B1,8) to also read value in cell B1?
Thanks.
Regards,
Zaiem
Maybe what you would like is:
=IF(MAX(IFERROR(FIND(LEFT(A$1,8),B$1:B$5),""))=1,"Duplicate","")
entered with Ctrl+Shift+Enter

Use string value from a cell to access worksheet of same name

I have 2 worksheets: Summary and SERVER-ONE.
In cell A5 on the Summary worksheet, I have added the value SERVER-ONE.
Next to it, in cell B5, I would like a formula that uses the value in A5 to display the value of G7 in the worksheet of the same name (SERVER-ONE).
I could manually use:
='SERVER-ONE'!G7
However I would like this to be dynamic, so I can easily add more worksheets.
I tried the obvious with no joy:
='A5'!G7
Any suggestions?
You can use the formula INDIRECT().
This basically takes a string and treats it as a reference. In your case, you would use:
=INDIRECT("'"&A5&"'!G7")
The double quotes are to show that what's inside are strings, and only A5 here is a reference.
You need INDIRECT function:
=INDIRECT("'"&A5&"'!G7")
not sure if you solved your question, but I found this worked to increment the row number upon dragging.
= INDIRECT("'"&$A$5&"'!$G"&7+B1)
Where B1 refers to an index number, starting at 0.
So if you copy-drag both the index cell and the cell with the indirect formula, you'll increment the indirect.
You could probably create a more elegant counter with the Index function too.
Hope this helps.
Here is a solution using INDIRECT, which if you drag the formula, it will pick up different cells from the target sheet accordingly. It uses R1C1 notation and is not limited to working only on columns A-Z.
=INDIRECT("'"&$A$5&"'!R"&ROW()&"C"&COLUMN(),FALSE)
This version picks up the value from the target cell corresponding to the cell where the formula is placed. For example, if you place the formula in 'Summary'!B5 then it will pick up the value from 'SERVER-ONE'!B5, not 'SERVER-ONE'!G7 as specified in the original question. But you could easily add in offsets to the row and column to achieve the desired mapping in any case.
By using the ROW() function I can drag this formula vertically. It can also be dragged horizontally since there is no $ before the D.
= INDIRECT("'"&D$2&"'!$B"&ROW())
My layout has sheet names as column headers (B2, C2, D2, etc.) and maps multiple row values from Column B in each sheet.
INDIRECT is the function you want to use. Like so:
=INDIRECT("'"&A5&"'!G7")
With INDIRECT you can build your formula as a text string.
Guess #user3010492 tested it but I used this with fixed cell A5 --> $A$5 and fixed element of G7 --> $G7
=INDIRECT("'"&$A$5&"'!$G7")
Also works nested nicely in other formula if you enclose it in brackets.
This will only work to column Z, but you can drag this horizontally and vertically.
=INDIRECT("'"&$D$2&"'!"&CHAR((COLUMN()+64))&ROW())

Resources