Countifs and ranges - excel

I'm trying to write some code that requires a cell value to be within a range of dates.
This is what I have written so far (albeit a few name changes for simplicity):
=IF(COUNTIFS('[SheetA.xlsx]TabA'!A2:AA2, "submit", '[SheetA.xlsx]TabA'!B2:AB2, '[SheetA.xlsx]TabB'!**A9:A13**) >= 1, '[SheetA.xlsx]TabA'!C2, "")
Basically, if a cell in a row contains the word "submit" AND the cell to the right of it has a date (within a specific range of five days), I'd like the function to return the third cell of that row.
The range in bold is a range of dates.
This formula doesn't work when I use a range, but returns expected values when I enter a single date. What should I change?

As for COUNTIF() not finding a date in a range, if the range is consecutive, you can get around that like so:
COUNTIFS(A2:AA2, "submit", B2:AB2,">=" & LowestDate,B2:AB2,"<=" & HighestDate)
The problem there is that you're comparing a range to a range, so the whole range has to match the whole other range. This will always return false since the ranges are not even the same shape. When instead you compare a range to a single value, Excel automatically assumes you want true if the single value exists anywhere in the range.
It sounds like your other issue is that since COUNTIFS() does not return where it found "submit" and a date, the outer IF statement cannot determine where the third cell is.
If there's only going to be one submit, you could use Match("submit",2:2,0)+2 to find the relative column of "submit" add 2 to it, and then use ADDRESS() to build the address of the third cell based on the row. Last you put that inside of an INDIRECT() to return the third cell. Something like:
=INDIRECT(ADDRESS(ROW(A2),MATCH("submit",2:2,0)+2,1,1))
Note that this will not work for multiple matches as you're returning the first value MATCH() finds.
I use ROW() because ADDRESS() may not fill the row series very well when you drag the formula down a column if you use a plain row number.

Related

=ISNUMBER(SEARCH()) formula not working properly

Basically, im trying to search if values from column b is contained in cells on column a
I am currently using the formula
=ISNUMBER(SEARCH(B1,$A:$A))
and using it inside a conditional formatting to highlight the cells in column A that contains strings from column B. But it is not highlighting the correct cells
any advice?
Problem is that your ISNUMBER(SEARCH(…. formula is returning an array of values {FALSE;TRUE;FALSE;FALSE;...} one return for each item in within_text. You need to know if any of those items match.
So, with your formula, consider the array formula modification
=OR(ISNUMBER(SEARCH(B1,$A:$A)))
Since this is an array formula, you need to "confirm" it by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar
If you don't like to use the CSE entry method, you could use this formula which will return zero for no matches, or be non-zero for any matches:
=SUMPRODUCT(-ISNUMBER(SEARCH(B1,$A:$A)))
Excel's SEARCH function is used to find the position of one string within another string. Generally you use it like this:
=SEARCH("String A", "A Longer String Containing String A")
This will return the character index where first string starts within the second string, which in this case would be 28.
What you really need is a VLOOKUP. Since you're doing a textual search (substring), you need your range to be of text type instead of number.
You should do the following:
Add an extra column to the right of Column A and use TEXT function to convert entries to textual form:
=TEXT(A1, "#")
Now you can use VLOOKUP to perform a substring-match in this textual range. VLOOKUP supports wildcards when you do not ask it to perform an exact match (4th argument should be FALSE). Here is your formula then:
=VLOOKUP("*" & C1 & "*",$B:$B,1,FALSE)
Note that I have passed column B (textual column) as the lookup range, whereas C1 is the cell containing the text that you want to search.
This method also has the additional advantage that it returns the actual matched entry from the range so you don't have to find it manually.
Once you have your results, you can apply conditional formatting to it.
Highlight column A (or the relevant range in column A starting cell A1) with the first cell (which is A1 in this case) as the active cell, use the following formula as the conditional formatting rule:
=(SEARCH($B1,$A1)*(LEN($B1)>0))>0
The logic is to first search the given sub-string from the main string, then multiple the result by LEN($B1)>0 to exclude the result of 1 returned for blank cells in column B.
Note: Conditional Formatting works in array fashion so even though the formula only looks at values in the first row of the range, as long as you use the relative (or in some cases absolute) cell references correctly and highlight the result range correctly before setting up the rule, the rule will be applied across in the same way as for the first row of the array as demonstrated in this example.

Formula to rearrange order

I specify a value to be looked up in a range and then another
=IFERROR(INDEX($A$3:$A$5,MATCH(1,($A$6:$A$6<=$B$2)*($A$3:$A$5>=$B$2),0)),"")
It returns a blank cell(A7, expected result 25) for some reason when A6:A6 equals to a value of B2 but it finds a greater than equal to when its less, in the second range parameter.
What I need is first search a range and if not found search a second range. Can it be modified to search backward?
B2=22
A3=7
A4=25
A5=45
A6=2
A7=25
What I need is first search a range and if not found search a second
range.
We need to perform two separate lookups.
=IFERROR(VLOOKUP("h",A1:A5,1, FALSE), VLOOKUP("h",B1:B5, 1, FALSE))
Following formula attempts to look up "h" in array A1:A5, if it's not found, it performs VLOOKUPon the second array. Obviously, you can replace "h" with whatever cell reference you need, but the principle of the formula stays the same.

Returning value of matching cell in a dynamically changing range with formulas?

After hours of searching and trying I have conceded defeat and ask the wisdom of this community for help.
The Goal:
- Match Customer ID and return Value 1 and Value 2 for each date range. (area in red box)
Restrictions keeping me for getting an easy solution:
- Data cannot be modified in any way (area in black box), It is in another sheet and cannot have helper columns added to it
- Data is separated by a header that is constant with only date range changing, however data is dynamic in length
- Macros are not allowed on this worksheet, so solution must be a formula
Current angle of attack (for cell H2 only) :
=VLOOKUP(G1,("B"&(MATCH(G2,B:B,0)+ROW(B:B)-1)&":"&"D"&(MATCH(G3,B:B,0)+ROW(B:B)-1)),2,FALSE)
This tries to define the Vlookup range by matching the dates and inserting the found row numbers.
=("B"&(MATCH(G2,B:B,0)+ROW(B:B)-1)&":"&"D"&(MATCH(G3,B:B,0)+ROW(B:B)-1))
returns the correct range, but when it is inserted into the range target of Vlookup I get a Value Error. Another failing is that it would not work for the last section of data as it will be missing an end header with date.
Bellow is a very simplified version of the data i will be working with:
Thanks for any and all help on this head scratcher
If I understand your requirements correctly, what about the following to return Value1:
=VLOOKUP(G1,OFFSET(B1,MATCH(G2,B:B,0),0,IFERROR(MATCH("Dates",OFFSET(A1,MATCH(G2,B:B,0),0,COUNTA(A:A),1),0),COUNTA(A:A)),3),2,FALSE)
This uses the OFFSET function to establish your VLOOKUP range. Using the 4th and 5th parameters returns a range instead of a single cell.
Two of the MATCH functions look for the text of the date range specified in G2. The other MATCH function looks for the next instance of the text "Dates" after the G2 match; however, the IFERROR function protects the last range (since there is not another "Dates" cell) and makes the range as large as could be needed to cover the final date range.
To modify it to return Value2, change the "2" before the "FALSE" to be "3".

VLOOKUP in last column of Table_array

I understand that VLOOKUP searches the first column of a table in order to find a value, then it grabs the value from the same row and a different user-specified column. The following code returns data from the 2nd column, column B.
VLOOKUP(5,$A$2:B100,2)
Is there a way to set the return column to the last column of the input table? Something like the following, which would return data from columns B, P, and AC, respectively.
VLOOKUP(5,$A$2:B100,end)
VLOOKUP(5,$A$2:P100,end)
VLOOKUP(5,$A$2:AC100,end)
Alternatively, is there a way to grab the current column number and use that as an index?
VLOOKUP(5,$A$2:B100,current_column_number)
I'd like to write one VLOOKUP formula and then be able to drag it right across the spreadsheet, so that B100 becomes C100, D100, E100, etc. and the column lookup changes accordingly.
Update
I can do the alternate approach using the COLUMN function, but it requires programming a fixed offset and doesn't seem as robust. I'd still like to know if there is an "end" option.
=VLOOKUP(5,$A$2:B100,COLUMNS($A$2:B100))
Unfortunately you cannot simply drag it, you'll need to replace as there are two equivalent ranges written in the nested function.
The COLUMNS effectively counts the columns in the range giving the exact result needed for the VLOOKUP's end variant.
EDIT to show OP what a simple drag function would be like:
Function VLOOKUP2(Expected As Variant, Target As Range)
x = Target.Columns.Count
VLOOKUP2 = Application.WorksheetFunction.VLookup(Expected, Target, x)
End Function
You can use the Excel COLUMN() function to convert the column reference to a numerical index into the VLOOKUP table. Try this:
VLOOKUP(5, $A$2:B100, COLUMN(B2))
VLOOKUP(5, $A$2:P100, COLUMN(P2)
VLOOKUP(5, $A$2:AC100, COLUMN(AC2))
In pratice, you can just enter the first formula I gave above and then copy to the right. Each copy will automatically shift the column number to the end.
You could use the count function while holding ($) one side of the count range, thus giving you an integer that Vlookup can use.
Something like:
VLOOKUP(5,$A$2:B100,COUNT($A$2:A2))
You may need to add a + or - 1 to the count function depending on where your range starts.
It's effectively doing the same thing you already did with the array for the vlookup

Need some type of IF...MOVE

In a range of G4:G19, I am looking for "Winner" and when I find it, I want to MOVE (from the same row), the information in column D of that row to the cell in which I am writing the formula.
=IF(LARGE(G$4:G$19,1)="Winner", ...)
... move the contents in column D (of that row) to D25 which is where I want to place the formula.
I cannot be specific about the cell because it will be different depending on the cell that contains "Winner".
I need some kind of move statement.
I'm not sure why you're using LARGE, since it only works with numbers, and so only returns numbers, which don't make sense to compare with the text "Winner", but...
From the what you've described, it sounds like something like the following formula in cell D25...
=INDEX(D$4:D$19,MATCH("Winner",G$4:G$19,0),1)
...might meet your needs. The MATCH expression finds the relative position of the first cell it finds containing the exact (indicated by the 0) text "Winner" (case-insensitive) in the range G$4:G$19. The INDEX expression returns the value in this row and the first column (indicated by the 1) of the range D$4:D$19.

Resources