Query returning 1st cell in range although condition is not met (Google Sheets) - sql

I'm a first time query-user, so I'm out of my depth for fixing this myself.
Here's what I have and am looking to accomplish in two separate Google Sheets spreadsheets:
Spreadsheet1 - column A contains a list of names, column B contains a checkbox for true or false
Spreadsheet2 - import list of names from Spreadsheet1 column A where column B is true (and transpose the names so they appear in columns)
This is the formula I'm using in Spreadsheet2:
=TRANSPOSE(QUERY(IMPORTRANGE(LinkToSpreadsheet1,"Sheet1!A39:B51"),"Select Col1 where Col2 = TRUE",1))
The problem I'm facing is:
When column B in Spreadsheet1 contains only FALSE results, the formula is still returning cell A39 as the result, rather than returning no result.
I've also tested that when column B in Spreadsheet1 does contain a TRUE result (for example cell B48 = TRUE), but A39 is FALSE -- it is still returning cell A39 in addition to the matching TRUE cell of A48.

The problem I'm facing is:
When column B in Spreadsheet1 contains only FALSE results, the formula is still >returning cell A39 as the result, rather than returning no result.
that's because you use 1 as 3rd query parameter. you should use 0. try:
=IFERROR(TRANSPOSE(QUERY(IMPORTRANGE(LinkToSpreadsheet1,"Sheet1!A39:B51"),
"select Col1 where Col2 = TRUE", 0)))

Related

Excel VBA - Searching a column for a particular value and returning the value from the adjacent cell

I'm a total noob at VBA and need all the help I can get so I apologise in advance for the dumb question. I feel its the only way I will learn.
I have a spreadsheet with two columns, I simply want to search column A for a particular value (I know what this value is, so can hardcode the value into the code) and return the value in column B and assign it to a variable.
Column A Column B
Parameter Value
TabDocumentPath Path 1
FrameworkPath Path 2
FrameworkAllFile Path 3
FrameworkFullPath Path 4
AssembliesPath Path 5
So for example if you look at the above, I would like to search for AssembliesPath in Column A and assign the value in the adjacent cell (Path 5) to a variable.
I know, its quite simple but I cannot seem to find this when I search the archive here.
Any help would be greatly appreciated.
You can use the WorksheetFunction.VLookup Method for this
VariableName = Application.WorksheetFunction.VLookup("Parameter", Worksheets("Worksheet1").Range("A:B"), 2, False)
Parameter = lookup value
we want to lookup "Parameter"
Parameter = lookup range
our lookup and return data is in columns A:B of the worksheet named Worksheet1
Parameter = column index (of lookup range) to return
we want to return the value of column 2 of the lookup range (this is B)
Parameter = exact match or an approximate match
False means exact match

Marking repeating or both in corresponding cell based on the criteria

i have a sheet in excel which have two columns Col "A" & Col "B"
in col "A" i have values like 1,1,1 - 3 times & 2,2,2,2 - 4 times
and in col "B" i have yes, yes, yes corresponding to column A value 1,1,1 &
yes, no ,yes no corresponding to column "A" value 2,2,2,2 as shown in the image.
now i want to add some values in col "C" based on codition like
if col "A" 1,1,1 all values are yes in col "B" then put SOME TEXT LIKE "repeating" in Col "C" in front of every value of col"A"
and if col "A" 2,2,2,2 all values are different like yes, no, yes , no in col "B" then put SOME TEXT LIKE "both" in Col "C" in front of every value of col"A"
for example see below image.-
-it will check all the similar values in col "A" First suppose it will take "1" first then it will check its corresponding value in col "B" and it will keep on checking all of the values of "1" in col"B" if all values are "yes" then it will simply put "repeating" in col"C" in front of every "1"
-but again it will check for all the values of "2" in col"B" if all values are "yes" then it will simply put "repeating" in col"C" in front of every "2" but as you can see all values are not same in front of "2" some are "yes" and some are "no" in col"B" so if all values of "2" are not same in col "B" then it will put "both in col"C" in front of every "2"
i want to know is there any formula for doing this or vba code is needed . please help me regarding this.
If you have Excel 2016 you can use COUNTIFS nested in an IF like:
Countifs will count the values based on two criteria.
=IF(COUNTIF($A$1:$A$7,A1)=COUNTIFS($A$1:$A$7,A1,$B$1:$B$7,B1),"Repeating","Both")
You can nest a third condition like this:
=IF(B1="may be","Confirm",IF(COUNTIF($A$1:$A$9,A1)=COUNTIFS($A$1:$A$9,A1,$B$1:$B$9,B1),"Repeating","Both"))
Explanation:
The formula consists of two conditional IFnested:
The first IF(B1="may be","Confirm" evaluates if B1 = "may be" when is
true it returns "Confirm".
when is false start the second IF to compare one condition:
COUNTIF($A$1:$A$9,A1) - Countsif function counts values in a range
based on one condition. In this case, the criteria are each cell in
column A and count how many times are this value in the range
$A$1:$A$9.
COUNTIFS($A$1:$A$9,A1,$B$1:$B$9,B1) - Countifs function counts
values in a range based on multiple conditions. In this case, it is
counting based on two criteria for each value in A and B.
Evaluating second conditional:
For C1:
COUNTIF($A$1:$A$9,A1) = 3 3 times the value (1) in the range
$A$1:$A$9.
COUNTIFS($A$1:$A$9,A1,$B$1:$B$9,B1) = 3 3 times the values (1) and (yes).
So, if 3 = 3 then "Repeating".
For C4:
COUNTIF($A$1:$A$9,A4) = 4 4 times the value (2) in the range
$A$1:$A$9.
COUNTIFS($A$1:$A$9,A4,$B$1:$B$9,B4) = 2 2 times the values (2) and (yes).
So, if 4 = 2 is false it returns "Both".

If Cell Matches another Cell, Copy Value

I can't seem to figure this one out. I have two work sheets with some of the same ids, but if an id matches on one sheet with another I need it to see if the status is Routed and if it is, then I need a y placed in Column B of the related number.
So for example:
Worksheet 1
-----A--------B
1--**4345**---Routed
2--5643---Completed
3--3423---Routed
4--2342---Routed
Worksheet 2
-----A-------B
1--9876----n
2--5678----n
3--**4345**----y
4--1234----n
So if there is a match in column A between the two worksheets then I need it to search for Routed in Column B on Worksheet 1.
If the word Routed is there, then I need it to add a "y" to the previously matched id in column B of Worksheet 2, otherwise if the id is not found or if it matches, but no routed (rather it be blank or something else [completed, done, ect]) then I need an n in column B.
This works. Place the below formula in Sheet2. You can paste it down as many rows as you like as it is relative.
=IF(NOT(A1=Sheet1!A1),"",IF(Sheet1!B1="routed","y","n"))
Inserting a VLOOKUP() function into an IF() function will test whether the looked-up value meets the specified condition, and return the specified values if TRUE ("y") or FALSE ("n"): =IF(VLOOKUP(A2, SHEET1!$A$1:$B$4, 2, FALSE)="Routed", "y", "n"). You can enclose the entire formula in IFERROR() to account for IDs in Sheet2 that are not in Sheet1: =IFERROR(IF(VLOOKUP(A2, SHEET1!$A$1:$B$4, 2, FALSE)="Routed", "y", "n"), "n").
Per comments: If you want to find any cell containing the text "Routed" (but possibly with other text as well), you can change the VLOOKUP(. . .) = "Routed" condition to a test of whether the SEARCH() function finds the text: =IF(ISNUMBER(SEARCH("Routed", VLOOKUP(A2, SHEET1!$A$1:$B$4, 2, FALSE))), "y", "n"). Again, you can enclose this in IFERROR().

Count IF multiple criteria/data types match

I'm looking to generate a report to list the number of Cities/Towns that don't meet a certain criteria so on Sheet 2 I have an alphabetical list of all the cities/towns.
I want to do a look up/count if function to state if A2(Sheet 2) can be found anywhere in Column D on Sheet 1 then count it if the date in column L (sheet 1) matches the date in Cell $E$1 (sheet 2) and Column A in Sheet 1 is greater than zero.
I originally done this formula but it is returning an error.
=COUNTIFS(PickData!D:D,Sheet1!A2,PickData!L:L,Sheet1!$E$1,PickData!A:A,PickData!A:A>0)
Is there any other formulas that I'm currently not thinking of? Or is it possible to do this via VBA and it returns the value in to column B either True if it matches or False if it doesn't?
Thanks
Al
The problem with your previous formula is in the final criteria. Update to:
=COUNTIFS(PickData!D:D,Sheet1!A2,PickData!L:L,Sheet1!E2,PickData!A:A,">0")

Excel: Check if cell string value exists in column, and get all cell references to that string

I suspect this may be a job for VBA, which is beyond my abilities. But here's the scenario:
Column A in Sheet 1 (CAS1) contains x rows of text values
Column A in Sheet 2 (CAS2) contains x rows of text values
Part A - For each row value in CAS1, I need to know if the string is contained in any of the cells in CAS2. Not exact match, the string can be only part of the searched cells.
Part B - I need to know the cell value of each cell in CAS2 that contains the CAS1 value (if they do exist, they can be listed in the cells adjacent to the cell being searched in CAS1).
I've tried the following to attempt Part A, all to no avail:
vlookup(A1,sheet2!A:A,1,false)
NOT(ISNA(MATCH(A1,sheet2!A:A,0)))
ISNUMBER(MATCH(A1,sheet2!A:A,0))
COUNTIF(sheet2!A:A,A1)>0
IF(ISERROR(MATCH(A1,sheet2!A:A, 0)), "No Match", "Match")
I know some of the cell values in CAS2 contain the cell values in CAS1, so I don't know why they return false or No Match. I suspect it may be down to the nature of the text content. So here's some sample data:
CAS1
LQ056
RV007H
RV008
RV009H
TSN304
TSN305
CAS2
RV009-satin-nickel-CO.jpg
STR314.jpg
STR315.jpg
HCY001.jpg
RV008-oval-rad-CO.jpg
HCY001-BRAC006.jpg
Any help would be appreciated.
This problem can be faced through VBA (at least, I imagine the VBA solution much more easily than the possible Excel one). You need a macro that, for each row in CAS1, search the content in each row of CAS2 and returns you the address.
For Each cell In Sheets("CAS1").Range("A1:A" & Sheets("CAS1").Range("A1").End(xlDown).Row) '<-- check each cell of the range A1:A? of sheet CAS1 (adapt "A" and "1" if they're different)
recFound = 0 '<-- count how many findings there are
For Each cell2 In Sheets("CAS2").Range("A1:A" & Sheets("CAS2").Range("A1").End(xlDown).Row) '<-- check in each cell of the range A1:A? of sheet CAS2 (adapt "A" and "1" if they're different)
If InStr(cell2.Value, cell.Value) <> 0 Then '<-- if the value in cell is contained in the value in cell2..
recFound = recFound + 1 '<-- account the new finding
cell.Offset(0, recFound) = Split(cell2.Address, "$")(1) & Split(cell2.Address, "$")(2) '<--write the address on the right of the currently searched cell
End If
Next cell2
Next cell
All the above should be enclosed in a macro, e.g. Sub makeMySearch(), that should be run to get the results. As commented in my code, I'm assuming that data are in A1:A? of both sheets; but they of course might be, for example, in B5:B? of the sheet 1 and in C7:C? of the sheet 2. You need clearly to adapt the code to your current data.
There's no need for VBA. Some simple array-formulas can do the job.
To see if the entry in CAS1 is present in CAS2:
=OR(ISNUMBER(SEARCH(A2,CAS2_)))
will return TRUE or FALSE. BUT this formula has to be entered by holding down CTRL-SHIFT while hitting ENTER If you do this correctly, Excel will place braces {...} around the formula that you can see in the formula bar.
The SEARCH function returns an array of results, which will be either the #VALUE! error, or a number.
In order to return the address, the following array-formula can be entered adjacent to a cell in CAS1:
=IFERROR(ADDRESS(LARGE(ISNUMBER(SEARCH($A2,CAS2_))*ROW(CAS2_),COLUMNS($A:A)),1),"")
Fill right for the maximum number of addresses possible, then select the group and fill down.
In this case, the array being returned is a string of either 0's, or 1 * the row number (i.e. the row number). I assumend the data in CAS2 was in column A, but you can change the column number if needed (or even compute it if necessary, by replacing the 1 in the ADDRESS function with COLUMN(CAS2_))
CAS1_ and CAS2_ are either named ranges, or absolute range references to the two text groups.