Custom Data Validation with possible Number or Word - validation

Ok so here is what I have so far. The following works properly preventing non numbers and more than 2 occurrences of each number.
=AND(ISNUMBER(K2),COUNTIF(K$2:K$20,K2)<3)
Next I need to add in the option for the field to be 'BYE'.
So each of the cells can contain a number that cannot occur more than twice or it can contain 'BYE'
Anyone have any advice on how to achieve this? Is there a way to say it can be like this or like that?

You could use OR.
=OR(K2="BYE",AND(ISNUMBER(K2),COUNTIF(K$2:K$20,K2)<3))

Related

Is there a way to change the way Google Sheets Query Group sorts? By both capitals and letter case?

I have a simple query function that returns a range of names and sums, grouped by the names.
=QUERY('Mamut inklipp'!C:R;"select F, sum(R) group by F";0)
This sorts by the names, but case sensitive. A-Z all comes before a-z. Therefore "Eve" comes before "adam". To me that is just plain wrong.
Is there a way to change the the sorting method?
You should be able to work around that. Pre-processing the data ('before the query') might be an option. Here's a little example.
I hope that works for you?
Note: Depending on your locale, you may have to use commas instead of semi-colons as argument separators (in the formula).

How do I write a regex for Excel cell range?

I need to validate that something is an Excel cell range in Ruby, i.e: "A4:A6". By looking at it, the requirement I am looking for is:
<Alphabetical, Capitalised><Integer>:<Integer><Alphabetical, Capitalised>
I am not sure how to form a RegExp for this.
I would appreciate a small explanation for a solution, as opposed to purely a solution.
A bonus would be to check that the range is restricted to within a row or column. I think this would be out of scope of Regular Expressions though.
I have tried /[A-Z]+[0-9]+:[A-Z]+[0-9]+/ this works but allows extra characters on the ends.
This does not work because it allows extra's to be added on to the beginning or end:
"HELLOAA3:A7".match(/\A[A-Z]+[0-9]+:[A-Z]+[0-9]+\z/) also returns a match, but is more on the right track.
How would I limit the number range to 10000?
How would I limit the number of characters to 3?
This is my solution:
(?:(?:\'?(?:\[(?<wbook>.+)\])?(?<sheet>.+?)\'?!)?(?<colabs>\$)?(?<col>[a-zA-Z]+)(?<rowabs>\$)?(?<row>\d+)(?::(?<col2abs>\$)?(?<col2>[a-zA-Z]+)(?<row2abs>\$)?(?<row2>\d+))?|(?<name>[A-Za-z]+[A-Za-z\d]*))
It includes named ranges, but the R1C1 notation is not supported.
The pattern is written in perl compatible regex dialect (i.e. can also be used with C#), I'm not familiar with Ruby, so I can't tell the difference, but you may want to look here: What is the difference between Regex syntax in Ruby vs Perl?
This will do both: match Excel range and that they must be same row or column. Stub
^([A-Z]+)(\d+):(\1\d+|[A-Z]+\2)$
A4:A6 // ok
A5:B10 // not ok
B5:Z5 // ok
AZ100:B100hello // not ok
The magic here is the back-reference group:
([A-Z]+)(\d+) -- column is in capture group 1, row in group 2
(\1\d+|[A-Z]+\2) -- the first column followed by any number; or
-- the first row preceded by any character

Using IN operator at tablix filters issue

I'm trying to add a filter with IN operator to my tablix. Problem is , my criteria values are already comma separated like A,B and C,D. Writing them like " 'A,B','C,D' doesn't seem to work.
I couldn't manage to get the filter working and all other questions/examples are for single word criteria. Any help?
I managed to fix this issue on my own by using a =split("2B,2C",",") function and changing the split notation (the last ,) to something other than a comma. Works very fine.
I hope this would help and save time for other people in future.

currency validation sholdn't allow zero or a number starts with zero

I have written a regex for currency which shouldn't accept 0 or a number starts with 0
/^\$?(?:\d+|\d{1,3}(?:,\d{3})*)(?:\.\d{1,2}){0,1}$/
But it still accepts 0 and numbers starts with 0.
In general, matching negatives with regular expressions is not the easiest thing to do. One option that would probably make your code more human readable is using multiple regular expressions, e.g., first
if (not /^\$0/)
if (/whatever else you do want it to match/)
// whatever
I think you want /^\$?(?:[1-9][0-9]*|[1-9][0-9]{0,2}(?:,[0-9]{3})*)(?:\.[0-9]{2})?$/. Not sure if that's exactly what you need, but the main point is to match [1-9] for leading digit.
Edit: doesn't allow $.99, but your example doesn't either so not sure if you want that.

Using Regex to grab multiple values from a string and drop them into an array?

Trying to grab the two $ values and the X value from this string in Ruby/watir:
16.67%: $xxx.xx down, includes the Policy Fee, and x installments of $xxx.xx
So far I've got:
16.67%:\s+\$(\d+.\d{2})
which grabs the first xxx.xx fine, what do I need to add to it to grab the last two variables and load this all into an array?
You can use the following, but regex may be unnecessary if the surrounding text is always the same:
\$(\d+.\d{2}).*?(\d+) installments.*?\$(\d+.\d{2})
http://www.rubular.com/r/sk5wO3fyZF
if you know that the text in between will always be the same you could just:
16.67%:\s+\$(\d+.\d{2}) down, includes the Policy Fee, and x installments of (\d+.\d{2})
You better use scan.
sub(/.*%/, '').scan(/\$?([\d\.]+)/)
Have you considered just splitting the string on the $ character?, then manipulating what you get with a regex or basic string commands?
/\$(\d+.\d{2}).+\$(\d+.\d{2})/ should do it. it wont matter what text is there, only that there are two "$" in the sentence.

Resources