Use cell number in cell reference in query - google-sheets

I have this formula:
=query(A6:D848,"Select * where D LIKE'"&AC1&"' AND A <> 'Grand Total'",0)
Where AC1 has a value of 2 in it.
The above works a treat, but when I try to change the LIKE to a >, I get an error.
=query(A6:D848,"Select * where D >'"&AC1&"' AND A <> 'Grand Total'",0)
I'm assuming that it's because referencing a cell value gives back a string value an not an number, but I can't figure out how to get it to change to an number and make the query work.

=query(A6:D848,"Select * where D > "&AC1&" AND A <> 'Grand Total'",0)
You received the error, because you had several quotes there.
'"&AC1&"' = ' + " + &AC1& + " + '
You needed to remove the single quotes, because those were required for LIKE and not needed for >.

Related

Convert this array formula for google spreadsheet

I found out that you can't use an array formula if you are using the "if" "and" "or" formula on google spreadsheet. Can someone please help me fix this formula I made, if possible I still want it to be an array formula
=ArrayFormula((IF(AND(H7:H="NSW",K7:K>=59,M7:M="Yes",OR(N7:N="Yes",O7:O="Yes"),OR(P7:P="Yes",P7:P="Unsure"),OR(Q7:Q="Yes",Q7:Q="Unsure"),S7:S="Yes",OR(T7:T="Yes",T7:T="Unsure"),OR(U7:U="No",U7:U="Unsure"),OR(V7:V="No",V7:V="Unsure"),OR(W7:W="No",W7:W="Unsure"),OR(X7:X="No",X7:X="Unsure"),OR(Y7:Y="No",Y7:Y="Unsure"),OR(Z7:Z="No",Z7:Z="Unsure")), "Passed", "Failed")))
Here is also the link to the spreadsheet: https://docs.google.com/spreadsheets/d/1F6P7oynTDzckDFMd279ON1udFYWSfo3gUX1Kw2RjDbE/edit?usp=sharing
If you remove the word arrayformula, it work just perfectly fine but I'm using this formula for google sheet responses so I would really need it to be an array formula
You haven't provided a link to the spreadsheet, so what I'll share below is constructed by eye and is not tested. But you can try this:
=ArrayFormula( IF( (H7:H="NSW") * (K7:K>=59) * (M7:M="Yes") * ((N7:N="Yes") + (O7:O="Yes")) * ((P7:P="Yes") + (P7:P="Unsure")) * ((Q7:Q="Yes") + (Q7:Q="Unsure")) * (S7:S="Yes") * ((T7:T="Yes") + (T7:T="Unsure")) * ((U7:U="No") + (U7:U="Unsure")) * ((V7:V="No") + (V7:V="Unsure")) * ((W7:W="No") + (W7:W="Unsure")) * ((X7:X="No") + (X7:X="Unsure")) * ((Y7:Y="No") + (Y7:Y="Unsure")) * ((Z7:Z="No") + (Z7:Z="Unsure")), "Passed", "Failed") )
In array formulas, the equivalent of AND is *; and the equivalent of OR is +.
ADDENDUM (after additional comment and sharing of link to spreadsheet)
Erase everything from Column AB (including the header) and place this in cell AB1:
=ArrayFormula( IF(A:A="",, IF(ROW(A:A)=1, "Eligibility", IF( (H:H="NSW") * (K:K>=59) * (M:M="Yes") * ((N:N="Yes") + (O:O="Yes")) * ((P:P="Yes") + (P:P="Unsure")) * ((Q:Q="Yes") + (Q:Q="Unsure")) * (S:S="Yes") * ((T:T="Yes") + (T:T="Unsure")) * ((U:U="No") + (U:U="Unsure")) * ((V:V="No") + (V:V="Unsure")) * ((W:W="No") + (W:W="Unsure")) * ((X:X="No") + (X:X="Unsure")) * ((Y:Y="No") + (Y:Y="Unsure")) * ((Z:Z="No") + (Z:Z="Unsure")), "Passed", "Failed") ) ) )
This will produce the header and all results. Blank rows will be left blank. Current results are checked and correct.
It's best to use a whole column approach (e.g., A:A in the top cell instead of A2:A in the second cell) since the sheet that contains the formula is using a QUERY to bring in that information and in case you ever decide to use sorting.

Lua pattern matching problem with escaped letter

I've already had a rule that \ should be replaced with \\\\
, so the existed code is
string.gsub(s, '\\', '\\\\\\\\')
but there is some data that should not be converted, such as abc\"cba, which will be replaced with abc\\\\"cba.
How can I constraint that only \ followed without " can be replaced, such like
'abc\abc' -> 'abc\\\\abc'
'abc\"abc' -> 'abc\"abc'
I have used patterns like \\[^\"]- and \\[^\"]+- but none of them works.
Thanks
You can use
string.gsub((s .. ' '), '\\([^"])', '\\\\\\\\%1'):sub(1, -2)
See the online demo:
local s = [[abc\abc abc\"abc\]];
s = string.gsub((s .. ' '), '\\([^"])', '\\\\\\\\%1'):sub(1, -2)
print( s );
-- abc\\\\abc abc\"abc\\\\
Notes:
\\([^"]) - matches two chars, a \ and then any one char other than a " char (that is captured into Group 1)
\\\\\\\\%1 - replacement pattern that replaces each match with 4 backslashes and the value captured in Group 1
(s .. ' ') - a space is appended at the end of the input string so that the pattern could consume a char other than a " char
:sub(1, -2) - removes the last "technical" space that was added.

Making a print function repeat on a new line everytime it prints

So I want this final print function to print its function on a new line every time it prints. I've tried various "\n" placements to make it work but to no avail. Any tips?
from datetime import date
currentYear = date.today().year
print('Hi. What is your name?')
name = input()
while True:
try:
print('How old are you, ' + name + '?')
age = int(input())
if age >= 0:
break
else:
print('That is not a valid number.')
except ValueError:
print('That is not a valid number')
ageinHundred = 100 - int(age)
y = currentYear + int(ageinHundred)
t = 'You will be 100 years old in the year ' + str(int((y)))
print(t)
print('Give me another number')
num = input()
f = (int(num) * t)
print(f)
I want the final print function (print(f)) to print f multiple times on a new line each time. Not one after the other like the above code does now.
Thanks!
Change the last couple of lines to:
# Put t inside a list so it does list multiplication instead
# of string multiplication
f = int(num) * [t]
# Then join the individual f-lists with newlines and print
print("\n".join(f))
For the f = line, inspect f to get a better idea of what's going on there.
For the join part, join takes a list of strings, inserts the given string (in this case "\n"; a newline), and "joins" it all together. Get used to using join. It is a very helpful function.
Try this:
from datetime import date
currentYear = date.today().year
print('Hi. What is your name?')
name = input()
while True:
try:
print('How old are you, ' + name + '?')
age = int(input())
if age >= 0:
break
else:
print('That is not a valid number.')
except ValueError:
print('That is not a valid number')
ageinHundred = 100 - int(age)
y = currentYear + int(ageinHundred)
t = 'You will be 100 years old in the year ' + str(int((y)))
print(t)
print('Give me another number')
num = input()
for i in range(0,int(num)):
print(t)

Rails - String concatenation issue while processing an array

I am trying to process the results of an array into a string to pass for a search. I want to build a string from the array that would look something like
("categories.name like '%Forms%' or categories.name like '%Apples%'")
serialize :category, JSON
if category.count > 1 && category.index != 0
$search_global.category.each do |cat_name|
cat_name.slice '" '
# cat_name
$array_count = $array_count + 1
if cat_name != ''
$inside_count = $inside_count +1
$cat_name_2 = "categories.name like %" + $cat_name_2 + cat_name + "% or " + $inside_count.to_s
end
end
end
If I select one item, it works fine as in
categories.name like %Forms% or 1
Please note that I am including the inside count just to get a better idea of what is happening.
The problem I have is when I select 2 or more items. categories.name like % is repeated twice and then the array items or listed as in
categories.name like %categories.name like %Calendar% or 1Forms% or 2
I can't seem to figure out why the concatenation isn't working as I expected.
$cat_name_2 = "categories.name like %" + $cat_name_2 + cat_name + "% or " + $inside_count.to_s
Your are using $cat_name_2 as the asignee as well as inside the assignment statement.

VBA parse string Place values to new columns

I have a sheets with the rows of data like.
NOM(LSL,USL)=207.3980(206.1990,208.5970) NOM(LSL,USL)=207.3980(206.1990,208.5970) NOM(LSL,USL)=18.8200(18.4400,19.2100)
I would like to just grab the Values and place them in their own cells like
207.3980 207.3980 18.8200
206.1990 206.1990 18.4400
208.5970 208.5970 19.2100
I continue to recieve "ByRef Argument Mismatch" errors. I believe relating to how I am defining the reference cell.
Sub Parse_Replace()
Dim i As Double
Dim ws As Worksheet
Set ws = ThisWorkbook.ActiveSheet
Dim Col As Range
Dim rLastCell As Range
Set rLastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
For i = rLastCell.Column To 1 Step -1
Col = ColLett(rLastCell.Column)
Columns(i).Cells(4) = SplitString(Col3, ",", 4)
Columns(i).Cells(5) = SplitString(Col3, ",", 5)
Columns(i).Cells(6) = SplitString(Col3, ",", 6)
Next i
End Sub
Function ColLett(Col As Integer) As String
If Col > 26 Then
ColLett = ColLett((Col - (Col Mod 26)) / 26) + Chr(Col Mod 26 + 64)
Else
ColLett = Chr(Col + 64)
End If
End Function
Function SplitString(pValue As String, pChar As String, pIndex As Integer) As Variant
Dim YString As Variant
YString = Replace(Replace(Replace(Replace(pValue, " ", ""), "=", ""), "(", ","), ")", ",")
SplitString = Split(YString, pChar)(pIndex - 1)
End Function
Process
Establish number of Columns with Data
Loop through each column
Convert column index to Column with ColLett
Set cell value with SplitString
Loop
Thank You
EDIT : replaced SplitString value with inteded.
You declare Col to be a range here:
Dim Col As Range
You then try to set Col to a string here:
Col = ColLett(rLastCell.Column)
When you set a range you have to set it to a range. Furthermore, you have to use the SET keyword to do so:
Set Col = <a range>
When you set that Col you set it only to the rLastCell.Column repeatedly in each loop of your For. If you just need that column letter for the last column, then do it before entering your for loop.
All of that is pointless anyway. At no point do you use the Column letter that you went through the trouble retrieving in your function. And really, for what you are doing you don't need the Column Letter. Column Letters are for humans; the column number is what is important in VBA any how.

Resources