Increment number along with a date on Google Sheets - google-apps-script

I would like to increment a cell in a column by 1 to 999. The thing is, it contains both a number and a date:
Item 1
001/2022
002/2022
003/2022
...
999/2022
Is there a way to do this? I assume it's possible to "hard code" the date as a string "2022" and increment the value beside it but, would it be possible to maintain the date format? If anyone can provide both answers and how to tackle them in each way, I'd be much obliged. Sorry if there is a reference to something like that, I just can't find it. I'm fairly new to this.

Place this in any cell with at least 998 open cells below it:
=ArrayFormula(TEXT(SEQUENCE(999),"000")&"/2022")

You could split the string by "/", parse & increment the left value and then rejoin the two parts like so:
function testIncrement() {
console.log(increment("005/2021"));
}
function increment(cellValue) {
const DIVIDER = "/";
let [a, b] = cellValue.split(DIVIDER)
return `${Utilities.formatString("%03d", parseInt(a) + 1)}${DIVIDER}${b}`;
}

Related

How to get a value after a character, from a string based on a text match using formula?

I got the following value:
tradicional;cropped$9$10;mullet$5$7
In cell A1, I can choose between tradicional, cropped and mullet. In cell A2, I pick 1, or 2.
If I pick cropped and 2, the value to be returned would be 10.
If I pick mullet and 1, the value to be returned would be 5.
If
I'd go for len and left, but I don't see how this is going to work using the matching criteria.
Here's a practical example: https://docs.google.com/spreadsheets/d/1dFzXmtKj15EzApTKUKv8yF7_mAIB1COPSgMLMMmFE4E/edit?usp=sharing
Appreciate your help.
Description
You can split the text string on semicolon ";" into 3 parts. The depending on which part you choose, you can split it on dollar sign "$" then you can get the "item" and return an integer. I leave it to you to figure out how to incorporate into your script.
Script (Test Case)
function makeAChoice() {
try {
console.log("You chose "+getChoice("cropped",2));
console.log("You chose "+getChoice("mullet",1));
console.log("You chose "+getChoice("somethingelse",1));
}
catch(err) {
console.log(err);
}
}
function getChoice(choice,item) {
try {
var text = "tradicional;cropped$9$10;mullet$5$7";
text = text.split(";");
text = text.filter( s => s.includes(choice) );
if( text.length < 1 ) throw "Error choice ["+choice+"] not found!";
text = text[0].split("$");
return parseInt(text[item]);
}
catch(err) {
console.log(err);
}
}
Console.log
8:32:38 AM Notice Execution started
8:32:38 AM Info You chose 10
8:32:38 AM Info You chose 5
8:32:38 AM Info Error choice [somethingelse] not found!
8:32:38 AM Info You chose undefined
8:32:38 AM Notice Execution completed
Reference
https://www.w3schools.com/jsref/jsref_split.asp
https://www.w3schools.com/jsref/jsref_filter.asp
https://www.w3schools.com/jsref/jsref_includes.asp
https://www.w3schools.com/jsref/jsref_parseint.asp
Per my comments to your original post, I feel that there is a lot we don't know about your bigger goal. But as you aren't able to provide that, this solution will work for your one exact example.
Place the following formula in C4:
=ArrayFormula(IFERROR(VLOOKUP(A4;SPLIT(FLATTEN(SPLIT(E4;";"));"$");B4+1;FALSE)))
(See the new sheet "Erik Help.")
The inner SPLIT splits the E4 string at every semicolon.
FLATTEN sends that all to one column.
The outer SPLIT then splits at each "$".
VLOOKUP can then try to find the Col-A term in the first column of the resulting virtual chart. If found, it will return the column value that matches the Col-B value + 1 (since column 1 of the virtual array is the labels, e.g., 'tradicional,' etc.).
If no match is found for both the Col-A and Col-B data, then IFERROR returns null.

Custom Condition Formatting, how to work with a String amount based condition in a Cell

I want to format cells with a custom function.
The cells have the content like so (without the ") :
Cell_1: "String1 String2 String3"
Cell_2: ""
Cell_3: "String1 String2 String3 String4 String5 String6"
if there is at least like 5 Strings in it, separated with a space it should be a true statement.
I tried to use a custom script like so, because im calling a function in this cell anyway, before returning the value i could set the format too:
var self = SpreadsheetApp.getActiveSheet().getActiveCell();
self.setFontWeight("normal");
if(returnValue.length>=5){
self.setFontWeight("bold");
}
return returnValue.sort().join(" ");
But i got a "You do not have permission to call setFontWeight" Exeption. After a little research i found that cunstom scripts are not allowed to cange format at all. Fine ... but how can i do it with the custom formatting condition
is something like this possible?:
=If(Split(?inputRange?;" ").length>=5;True;False)
If Yes how do i get the Range in the right format and which function is needed to get the String amount?
i tried also to write a custom function for that purpose:
function customFormat(input){
if(input.length>=5)
return true;
}
return false;
calling like so as custom condition:
=customFormat(range)
it seams like i cant use custom function there, i get no positiv result even than i return true always.
If you got some ideas how to accomplish this, i would be thankfull.
Assuming those three cells are in A1:A3
Apply conditional formatting to that range with the formula
=COUNTA(SPLIT(A1, " ")) >= 5

Adobe After Effects: Keep "Expression-Relations" when duplicating multiple layers

just wanted to ask, whether there is a way to keep the relations of expressions going when duplicating layers.
E.g. I have two layers, "LayerA" and "LayerB". Now I have an expression going on in "LayerB" saying, that its position always equals the position of "LayerA".
Now when I duplicate those two and get "LayerA 2" and "LayerB 2" I want the expression in "LayerB 2" to reference to "LayerA 2"'s position rather than "LayerA"'s position!
While it is no problem to simply change the expression when there is only one of them, it gets quite hard when you have multiple expressions going on ...
You might end up wanting to organize your comp differently, but, given your example (and exactly those name lengths), this position expression will work to find the appropriate 'target layer':
//base name to work from:
baseName = "Layer";
//length of that:
nameLen = baseName.length;
//this layer's name:
myName = thisLayer.name;
if (myName.length == nameLen) {
//if they are the same, then it is the original
// (non-duplicated) version
thisComp.layer("LayerA").transform.position;
} else {
//get tail string, the space and number:
tailStr = myName.substring(nameLen+1, myName.length);
//build new target layer name with "A":
targetName = myName.substring(0, (nameLen)) + "A" + tailStr
//new line pointing to target layer:
thisComp.layer(targetName).transform.position;
}

FB 4.6 - list component -- prepend labels with an item count?

I have a list component that uses a sqlite database as the dataProvider and am able to use labelField to show the data labels just fine... I want to, however, affix an incremental count before the label field so its listed as
1.) item number 1
2.) item number 2 ... etc...
I discovered labelFunct and wrote the following to test it out:
private function lblFunct(value:Object):String
{
return value.id + ") " + value.question;
}
and that shows the automatically assigned database ID before the label text just fine.... my goal is to try to get a COUNT of each item though... I can get the LENGTH of the data provider with
myListComponentID.dataProvider.length
but cant find any info on how to achieve an incremental count. is it possible to construct some sort of for each loop in the labelFunct? can anyone shed any light on this? Thanks in advance.
You're on the right track with the labelFunction. You can use getItemIndex method on your dataProvider to determine the itemIndex of the displayed item:
private function lblFunct(value:Object):String
{
return myListComponentID.dataProvider.getItemIndex(value) + ") " + value.question;
}
with help from the person who responded, I found my way to the solution... the fabel funct ended up looking like this:
private function lblFunct(value:Object):String
{
return (myListComponentID.dataProvider.getItemIndex(value)+1) + ") " + value.question;
}
I added the +1 to compensate for the fact that its zero based. thanks to the responder though, you helped me find my way to the answer. Much appreciated!

AdvancedDataGrid: dataTip = headerText

I have a pretty straightforward question which google fails to give me the answer to :
I have an AdvancedDataGrid where i build the columns dynamically (variable number of columns) in ActionScript, and i want the dataTip to display the column headerText when the user hovers over a cell. Adobe's example dataTipFunction:
private function tipFunc(value:Object):String
{
if (value is AdvancedDataGridColumn)
return "Column Name";
// Use the 'name' property of the data provider element.
return "Name: " + value["name"];
}
But in this case the value is only an AdvancedDataGrid column if the user hovers over a column header? I want the dataTip to always show the headerText for that column. So if i have to use this function, then how do i get the column headerText for a cell?
And as i understand the dataTipField i can't really use it to statically equal column.headerText (dataTipField = headerText).
Anyone have any pointers on how i can achieve this? It seems like a really easy task, still i can't seem to find out how :)
You can use a different function per column, which could be anonymous:
<AdvancedDataGridColumn dataTipFunction="{function(value:Object):String{return 'Data Tip'}}" ... />