Excel: Use Cell Range which is saved in a cell for completing a formula in another cell - excel

In the above Table i would like to use the range defined in V2 for the formula defined in E2. It should replace the green underlined part of the formula. As you can see there is already the right range in there but it is for flexibility reasons if the range changes so i don't have to change all the formulas which are in E2,F2,G2,... and so on.
The Formula:
=VLOOKUP("contract index",INDIRECT("'PURCHASING'!"&V2),2,FALSE)

Try,
=vlookup("contract index", indirect("'purchasing'!" & v2), 2, false)

Related

Three Dimension Vlookup

I have a master table with the following structure in excel :
How can I convert it as shown in the second picture by using the vlookup function? (function in yellow cells).
Three keys involved now: Daytime, User and Data Type (ADP_ERQ, ADP_SO)
Note: Column headers (Daytime, User, ADP_ERQ, ADP_SO) in the second picture are fixed.
Try this in C17 then fill right and down.
=INDEX($A$3:$Z$12, MATCH($A17, $A$3:$A$12, 0), AGGREGATE(15, 7, (COLUMN(1:1)+MATCH($B17, $1:$1, 0)-2)/($2:$2=C$16), 1))
For cell C17: IF(B17="USER_A",VLookup(A17,A3:C12,2,0),VLookup(A17,A3:E12,4,0))
For cell D17: IF(B17="USER_A",VLookup(A17,A3:C12,3,0),VLookup(A17,A3:E12,5,0))
In this formula replace A3:C12 and A3:E12 with your appropriate table range, then drag these down.

Nested conditional formatting for self referencing cells

I am formatting an excel sheet and want to apply a conditional format to a range of cells for when the particular cell matches the one either above or below it, AND when the corresponding cell in the adjacent column matches the cell either above or below it.
an example of the information in the columns:
Name Ref ID
PER 002-003
PPJ 021-006
PPJ 021-006
PPJ 021-006
RAD 005-013
REI 006-009
RIT 005-085
STJ 002-003
STJ 002-003
TEL 002-013
TEL 007-014
So in this section of the sheet PPJ & STJ should Highlight/fill but TEL should not since while the name matches the REF ID doesn't.
I have tried:
=AND(
OR(
INDIRECT(ADDRESS(ROW(), COLUMN())) = INDIRECT(ADDRESS(ROW(), COLUMN(),-1,0)),
INDIRECT(ADDRESS(ROW(), COLUMN())) = INDIRECT(ADDRESS(ROW(), COLUMN(),+1,0))
),
OR(
INDIRECT(ADDRESS(ROW(), COLUMN(),0,+1)) = INDIRECT(ADDRESS(ROW(), COLUMN(),-1,+1)),
INDIRECT(ADDRESS(ROW(), COLUMN(),0,+1)) = INDIRECT(ADDRESS(ROW(), COLUMN(),+1,+1))
)
)
but get no response from the cells regarding the formatting changes. I have tried substituting offset for the second OR statement referring to the adjacent column but get an error about too many arguments.
Am I taking an incorrect approach to this or am I missing a step?
You shouldn't need that level of complexity. For conditional formatting you can just apply the formula that applies to the top left cell of the range, so if your data is in D3:E14 for example then you only need to use the formula that applies to D3.....so follow these steps
Select the range to format (D3:E14 in my example)
Apply conditional formatting with the formula that applies to the top left cell of the range, i.e. for your problem
=AND(OR($D3=$D2,$D3=$D4),OR($E3=$E2,$E3=$E4))
Choose required format > OK > all done
Excel will implicitly adjust the conditional formatting formula for the whole "applies to" range as if you were dragging that formula on the worksheet, so it will work as required for the whole range
Given your sample data above here's the screenshot of that CF formula applied to your data:

conditional formatting of a cell when a cell name is used on a formula inside that cell

I am trying to apply conditional formatting to a cell when it contains an equation with reference to a named cell.
Example: Cell I71 contains the following equation. =G71*Admin_Labor_Rate
Admin_Labor_Rate has a value of $50, and is the name of cell B152.
Now I want to find all cells that reference cell B152 "Admin_Labor_Rate" and apply conditional formatting (highlight). I have two other Labor Rates, so I want to use cell highlighting to distinctly identify if the labor is being performed by technicians, admin, or engineering.
I have done a lot of research and tried a lot of methods, but it seems as close as I can get is if the cell equates to a certain value, then I can format it.
Thanks in advance for any thoughts the community may have on this.
Use this formula with conditional formatting:
=ISNUMBER(SEARCH("Admin_Labor_Rate", FORMULATEXT(A1)))
Where A1 is the top-left cell of the range you want to conditionally format. For example, you select range F20:H30 and enter the formula with F20 instead of A1.
Perhaps a User Defined Function (i.e. UDF).
function formulaContains(rng as range, nr as string) as boolean
formulaContains= rng.hasformula and cbool(instr(1, rng.formula, nr, vbtextcompare))
end function

Using IF Function Range in Excel

I have some problem in using If Excel function. I want to use range in excel. So when my data is in range, it will show something. I use this formula but it doesn't work "
=IF(E11=Rekap.C8:C21, VLOOKUP(Rekap.C8:C21, Master.A2:C148, 3), "")
Form that formula, if data in E11 is same like data in range C8 - C21 in Rekap sheet, it will show another data in Master sheet that in range A2-C148 column 3. How can I use range in if formula ?
A single cell like E11 cannot be compared to a range like C8:C21.
I assume that you really want to check if the value in E11 appears anywhere in the range C8:C21 and if so, perform the lookup. That can be done in several ways
=if(isnumber(match(e11,Rekap!$C$8:$C$21,0)),vlookup(E11,Master!$A$2:$C$148,false),"")
Note that I added the fourth parameter to the Vlookup. It will default to TRUE if omitted, which may return wrong results if the lookup table is not sorted.

Excel VBA Add formula based on row

So I have that table above, I use Excel VBA to add new prices then add the formula to Decision column.
As you can see, cell B2 formula should be =IF($A2>50000,"Ignore","Buy") and cell B3 formula should be =IF($A3>50000,"Ignore","Buy") so the formula in B2 refers to the value in A2, this is the same for B3 to A3 and so on. I use the VBA below to add the same formula to blank cells. Yes, there will be blank decision cells and they need formula. I must NOT use autofill from top to bottom. I tried using below (LastRow is the usedrange.row):
Sheet1.Range("B2:B" & LastRow).SpecialCells(xlCellTypeBlanks). _
Formula = "=IF($A2>50000,""Ignore"",""Buy"")"
The problem with that VBA is even in cell B5 the formula is =IF($A2>50000,""Ignore"",""Buy"") when it should be =IF($A5>50000,""Ignore"",""Buy"") (should be $A5 instead of $A2). What am I doing wrong?
With SpecialCells(xlCellTypeBlanks) you will probably get a non continuous range. With this the auto fill process will not work with A1 formulas. But with R1C1formulas it will.
Use:
.Range("B2:B" & lastrow).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=IF(RC1>50000,""Ignore"",""Buy"")"
RC1 means the Row you are currently in but always fix Column 1.
For R1C1 references see https://support.office.com/en-us/article/Overview-of-formulas-7abfda78-eff3-4cc6-b4a7-6350d512d2dc?CorrelationId=2bedf5ef-a3b7-4a82-9b12-6ee86b494ae9&ui=en-US&rs=en-US&ad=US#bmusing_references_in_formulas. Scroll down to The R1C1 reference style.
You can paste the formula in all cells, considering you have the formula in cell "B2":
Range("B2").Copy
Range("B2:B" & LastRow).PasteSpecial xlPasteFormulas
edit for more detail: You can use the R1C1 reference style, more importantly, R[1]C[1] notation. There is a caveat for different languages though, see the very end of the post. Examples:
R2C4 'row 2, column 4 so it's the cell D2 in A1-notation
R[2]C[4] 'the cell 2 to the right and 4 down from the current cell (where this reference is located)
R[2]C4 'the cell 2 to the right from the current cell in column 4 (D)
R[-2]C[-4] 'you can also give negative arguments, this is the cell 2 to the left and 4 up
R[2]C 'the same as R[2]C[0]
RC[4] 'the same as R[0]C[4]
R2C 'the same as R2C[0]
RC4 'the same as R[0]C4
R2 'row 2
C4 'column 4 (the same as D:D)
As you can see from the last three examples, the notations can't be mixed.
Now for your case:
If you want to have the following in cell Bx (replace x by any number)
"=IF($Ax>50000,""Ignore"",""Buy"")"
This would be the R1C1 formula
"=IF(RC1>50000,""Ignore"",""Buy"")"
or if it is more important that it is the column to the left:
"=IF(RC[-1]>50000,""Ignore"",""Buy"")"
The latter would be the like dropping the $ from the original formula.
Your second formula was
"=IFERROR(VLOOKUP(RC3,Database!$A:$F,3,FALSE),""Missing"")"
and Axel's answer
"=IFERROR(VLOOKUP(RC3,Database!C1:C6,3,FALSE),""Missing"")"
should be clear now.
If you don't want or can't use the formulaR1C1 property but still use the R1C1 style reference for a single cell, you can use the INDIRECT worksheet function. INDIRECT("R1C1",FALSE) is a reference to R1C1. The FALSE tells it to use R1C1 instead of A1 notation. It might behave slightly different than a simple reference if there is something other than numbers in the referenced cell.
I personally like the R1C1 notation better than the A1 notation mostly because it is easier to reference cells relative to the current position but also because it is easier to read for high column numbers and it's closer to the Cells(rowIndex,columnIndex) syntax.
One last thing: In other language versions of excel, R1C1 might be named differently. That doesn't affect the formula when you enter it via VBA (I think) but if you want to enter it from the worksheet, you need to keep that in mind. In German it's Z1S1 for example. This can also cause problems when opening the file with a different language version. If you used INDIRECT("R1C1",FALSE) in a formula, the INDIRECT and FALSE will be translated but the string will not so it will not work :( (The last part is from memory)

Resources