Vlookup with three comments depends on found value vba code or formula ( very hard to find solution) - vba

I have very difficult scenario where i need to mention three comments by tow V lookup. let me explain you situation.
We are getting three sheets in workbook with values every weekly.
sheet1 range A1 to A5 value , lookup values sheet2 range A:B and lookup value sheet3 range A:B. yes i can able to put two V lookup , but problem is 3 comments i need to show in single output.
When i lookup values found in sheet2 need comment as "found value in sheet2" , if not it has to lookup sheet3 range if found then it has to give comment as "found value in sheet3" and if value not found need to give comment as " invalid data".
through vba can is it possible and three comments should be sheet1 in a single output based on values?
am looked in google i can use IFSA formula and apply formula but i cant provide three comments ...
For us its really hard every weekend , Please help me with VBA Code or Any formula at one shot for three comments ?
Really appreciate your help

You can actually have up to 7 Nested (IF) functions in Excel - Nested Formula Limit
You need to make sure that you properly close each function. This can be seen when editing the formula, it will highlight the opening/closing parentheses as you arrow through the formula.
If it tries to select a range while using the arrow keys, hit F2 to toggle between Edit/Enter modes.
I think you want this...
=IF(ISNA(VLOOKUP(A1,Sheet1!A1:B4,2,FALSE)),IF(ISNA(VLOOKUP(A1,Sheet2!A1:B4,2,FALSE)),IF(ISNA(VLOOKUP(A1,Sheet3!A1:B4,2,FALSE)),"Invalid Data", "Sheet 3"),"Sheet2"),"Sheet1")
Actually, on second thought, I assume you want whatever is in Column B
=IFNA(VLOOKUP(A1,Sheet1!A1:B4,2,FALSE),IFNA(VLOOKUP(A1,Sheet2!A1:B4,2,FALSE),IFNA(VLOOKUP(A1,Sheet3!A1:B4,2,FALSE),"Invalid Data")))

If I understand correctly, you need to determine if the first VLOOKUP is found, and if not, use the second VLOOKUP. Thats super simple. Assuming the formula Profex provided doesn't work:
=IF(IFERROR(VLOOKUP("A1", Sheet2!A1:B4, 2, False), "Err")="Err",IFERROR(VLOOKUP("A1", Sheet3!A1:B4, 2, False), "Not Found"), VLOOKUP("A1", Sheet2!A1:B4, 2, False))

Related

SUMIFS returns 0 using dynamic criteria, with criteria range and sum range on another sheet

Anyone,
I've chatted with and called excel customer service with no luck. I used the formula builder (please see attached screenshot) to make sure each element of the formula is correct and returns the value for the criteria I'm trying to reference.
Everything is accurate, but it returns a value of 0. When I do the same thing in the actual sheet the data is stored in (and click a criteria cell within the criteria range) it returns the accurate value?! I'm not sure why it won't work on the other sheet. The values I am using to select are dynamic and change with a drop down. I have another, advanced, workbook (I did not create) that does the same thing and completes an even more complicated formula, but actually works so I'm not sure why this is returning a 0 value.
Photos and code/syntax: Dynamic Selection, Example 2 of it working, Example 1 of it working, Formula Builder, CountIFs, Advanced Spreadsheet working, VLOOKUP
=SUMIFS('GFEBS Pull'!Q:Q,'GFEBS Pull'!G:G,FMCOP!$C$20,'GFEBS Pull'!H:H,FMCOP!B23)
or:
=SUMIFS('GFEBS Pull'!Q:Q,'GFEBS Pull'!G:G,'FMCOP'!$C$20,'GFEBS Pull'!H:H,'FMCOP'!B23)
When I type ' around FMCOP sheet name, they disappear? I've also tried to lock the columns on the 'GFEBS Pull' sheet with no luck. Cell B23 is not locked because I'm going to copy the formula down to reference other cells. Any help is appreciated!
In this screenshot you can clearly see that both FMCOP!C20 ansd FMCOP!B23 have prefacing spaces; e.g. " HHC".
Since " HHC" will never match "HHC", fix the data returned from 'the lower table in the same screenshot'.
A Text-to-Columns, Fixed Width, Finish should do this. You could adjust the original formula like,
=SUMIFS('GFEBS Pull'!Q:Q, 'GFEBS Pull'!G:G, TRIM(FMCOP!$C$20), 'GFEBS Pull'!H:H, TRIM(FMCOP!B23))
I would caution against the latter 'bandaid' fix. Fix the original data; do not apply bandaids on-the-fly.

On a spreadsheet what does A:A and !A:A mean?

I have come across this sumif formula, I cant find any help doing a Google search on the N:N
=sumif(N:N,"Cat",C:C)
So I understand the SumIf, as per the docs:
SUMIF(range, criterion, [sum_range])
But I don't fully understand the N:N. Also please explain !A:A
Can someone provide an official explanation or point me to the docs.
N:N means that the range includes the whole column N, rather than just certain cells (e.g. N1:N300). This allows a formula to reference all data in the column even if you add more rows later on.
The exclamation mark is explained here: What does an exclamation mark before a cell reference mean?
When entered as the reference of a Named range, it refers to range on the sheet the named range is used on.
For example, create a named range MyName refering to =SUM(!B1:!K1)
Place a formula on Sheet1 =MyName. This will sum Sheet1!B1:K1
Now place the same formula (=MyName) on Sheet2. That formula will sum Sheet2!B1:K1
Note: (as pnuts commented) this and the regular SheetName!B1:K1 format are relative, so reference different cells as the =MyName formula is entered into different cells.
A clear answer to N:N was given. For the rest..
The exclamation mark in !A:A just means that you refer to another spreadsheet in your workbook -> say you currently work in Sheet2 and want to get Data from Sheet1. for this you have to use Sheet1 !A:A

percentile formula error in VBA

I'm trying to apply a formula through VBA for a particular range. This is the code in my VBA editor:
Sheets("WBR45").Range("AE105").Formula = "=PERCENTILE.INC(TP!$A$3:$A$30:$B$3:$B$30:$C$3:$C$30:$E$3:$E$30,50%)*24"
And the below formula gets updated in the destination cell when this is run:
=PERCENTILE.INC(TP!$A$3:$A$30:$B$3:$B$30:$C$3:$C$30:$E$3:$E$30,50%)*24
But I get an error in the destination cell as #VALUE!.
And when I click on "Show Calculation steps", only this part of the formula is underlined :
TP!$A$3:$A$30:$B$3:$B$30
I have no idea what is wrong with this simple formula. Can someone please take a look
Honestly I have no clue about what you're doing with this, but this may fix it:
"=PERCENTILE.INC(TP!$A$3:$A$30:TP!$B$3:$B$30:TP!$C$3:$C$30:TP!$E$3:$E$30,50%)*24"
You appear to have three errors in your formula:
You are using : to separate ranges instead of ,
You are not specifying which sheet the second, third and fourth ranges refer to, therefore it is defaulting to the sheet on which the formula occurs (i.e. sheet "WBR45")
Multiple ranges will need to be enclosed within brackets (...) in order to be passed as a single range.
If you are trying to have your function operate on the range A3:C30 together with the range E3:E30 (i.e. A3:E30 but ignoring column D), with those ranges being on the "TP" worksheet, I believe that you need to change your formula to
Sheets("WBR45").Range("AE105").Formula = "=PERCENTILE.INC((TP!$A$3:$A$30,TP!$B$3:$B$30,TP!$C$3:$C$30,TP!$E$3:$E$30),50%)*24"
or, slightly simplified
Sheets("WBR45").Range("AE105").Formula = "=PERCENTILE.INC((TP!$A$3:$C$30,TP!$E$3:$E$30),50%)*24"

get multiple column names (header) in table associated with particular value in to a cell

i need to get multiple column names (header) in table associated with particular value in to a cell
as i explained, i need to get the heading names corresponding to value "n" to column E.
i used the formula
=INDEX((A$1:D$1),MATCH("n",A2:D2,0))
here. but it only give one column name.
i am open to vba scripts also. but i think it doesn't need vba. just improve the the above formula, may be. i tried and failed. any help. thank you guys
if you are really "open" to vba, I'll use one simple UDF like:
Function HeatherNames(rg As Range, rf As String) As String
For Each cell In rg
If cell = rf Then HeatherNames = HeatherNames & Cells(1, cell.Column).Value & "-"
Next cell
HeatherNames = Left(HeatherNames, Len(HeatherNames) - 1)
End Function
you can use it in the column E `=HeatherNames(A2:D2;"n") now you can select the arg.1 (range) and type (or referring to another cell) the arg.2
Assuming you have Excel 2010 or later, in E2:
=IF(COLUMNS($A:A)>COUNTIF($A2:$D2,"n"),"",INDEX($1:$1,AGGREGATE(15,6,COLUMN($A2:$D2)/($A2:$D2="n"),COLUMNS($A:A))))
Copy to the right and down as required.
It would actually be slightly more efficient (and certainly if your dataset in reality is quite large) to have the initial IF clause held within its own cell, such that it is calculated for each row only once, rather than for each instance of the formula within that row. So a better set-up would be, in E2:
=COUNTIF($A2:$D2,"n")
copied down. Then, in F2:
=IF(COLUMNS($A:A)>$E2,"",INDEX($1:$1,AGGREGATE(15,6,COLUMN($A2:$D2)/($A2:$D2="n"),COLUMNS($A:A))))
copied to the right and down again.
Regards

Lookup function in multiple sheets data

I have multiple sheets of data and I want to make it in one sheet (All of them are in the same workbook). Link to the excel file.
I tried to use Hlookup function in excel file, something like below:
=HLOOKUP("University",Sheet1!$A$1:$G$2, 2, FALSE).
But, since I have more than 100 sheets of data, I want to find a way to drag the function and auto generate the function below the 2nd row. I have tried to use indirect function by setting a reference column in front as below but cannot deal with it.
=HLOOKUP("University", 'INDIRECT(A3)'!$A$1:$G$2, 2, FALSE)
My next option is VB code. But, I am new to VB. Anybody can help on it?
Place your individual sheet names in column H of the Summary sheet and the row number in column I (as helper columns) and write this formula in cell A2 of the summary sheet.
=IFERROR(HLOOKUP(A$1,INDIRECT($H2&"!A1:G"&$I2),$I2,0),)
and drag to column F and down for as many sheet rows combos you have. I used 10 rows but you can obviously make it longer or shorter as neeed.
When you are done you can filter on 0 in column A and remove any lines with no data.
If your sheet names have spaces in them, you'll need to adjust the INDIRECT formula to this:
INDIRECT("'"&$H2&"'!A1:G"&$I2)
best way would be "defined names" + INDIRECT + HLOOKUP (or LOOKUP) like:
defined names
name: SList
formula: =MID(TRANSPOSE(GET.WORKBOOK(1))&T(NOW()),FIND("]",TRANSPOSE(GET.WORKBOOK(1))&T(NOW()))+1,255)
formula in cells: (this in A2 then simply autofill to G2 and thenn everything down) (you'll get a row with 0's between the sheets, which can be filtered out or deleted later (copy/paste values))
=IFERROR(HLOOKUP(A$1,INDIRECT("'"&INDEX(SList,COUNTIF($A$1:$A1,0)+2)&"'!$A:$G"),$H2,0),"")
Set H2 to 2 and for H3: (autofill down from H3)
=MAX(($H2+1)*($A2>0),2)
works perfectly for me LINK
No manual typing of sheetnames or something like that (only Column H:H as helper). Youll get rows's with 0's every time a new sheet is selected which can be filtered out. (or if you copy/paste values also can be deleted)
the +2 at ...st,COUNTIF($A$1:$A1,0)+2)&... simply tells to start with sheet 2 (if summary is the first). You may change it to +1 if you want to lookup starting with the first sheet.
Assuming you already have all 100+ sheet names typed out in column A, this will work whether or not you have spaces in the sheet names:
=HLOOKUP("University", OFFSET(INDIRECT(ADDRESS(1,1,1,1,A2)),0,0,2,7),2,FALSE)