Need to change a sentence to add a word from a list in separate sheet - google-apps-script

Hi there and thank you for any support received in advance!
I have a Google Sheets document that has a list of towns in it in two columns on a separate tab and a series of default statements.
I would like to be able to run some form of script or code that automatically changes the "XXXX" and the "ZZZZ" to the appropriate text, as listed in the list of towns (on the second sheet) in any sentence and replaces it with a word from the list of towns. If someone is able to help I would really appreciate it and you can change that document as much as you'd like (it is a demo that I have set up for the purpose of asking this question). I would also appreciate a short explanation as to how you achieve the required result so I can learn and apply this in the future (without having to come back to S.O every time).
NOTE: I need to apply this for 1719 rows in the sheet, and cascade all of the text down it.
Edit: I have completed the first line of the sheet and completed it to the way we need it to be.

Change XXXXXX to ZZZZ and use newest formula
=arrayformula(if(len(C3:C), substitute(substitute(B2, "XXXX",list!A2:A),"ZZZZ",list!B2:B),))
Now no mixing XXXX and XXXXXX
For column B put this formula in cell B3.
For column D put formula in cell D3 and only change B2 to D2.
For column F put formula in cell F3 and only change B2 to F2.
For column L put formula in cell L3 and only change B2 to L2.
For column M put formula in cell M3 and only change B2 to M2. etc.
Like this do for every column you need.
Like other question now you do it 2 times. One for XXXX and one more for ZZZZ. That is why you do substitute again.
Because it is other tab you use list! for ranges there.

Related

Can I show the results of COUNTIF in one column only if there is data in another column?

I have a spreadsheet with multiple sheets.
Sheet A is generated from a template, and it is where users will enter in data to be formatted into a report; it will be deleted after that report is submitted.
As people enter info into Column A of Sheet A, they don't have to enter client information if we already have them entered in this spreadsheet, but otherwise they need to go over to Sheet B and enter it in.
To make it easier for them (so they don't have to check every time, or go back and enter info later after getting an error generating the report), I have used conditional formatting. The way it works is, column Z is set up as a helper column, and uses a "COUNTIF" function to check if the client ID in Sheet A, Column A is found in Sheet B, Column C. Sheet A Column Z returns 0 or 1 (or, theoretically, more than one if we had duplicates), and then Sheet A column A has conditional formatting based on Column Z's value-- if the client is already in, the cell for client ID turns green after they type it; if not, it turns red.
It works great! However, I am adding scripts to these sheets, and looping through them. This helper column is filled from Z1 to Z1000, which means I can't use sheet.maxRow() to get the last row.
I see plenty of workarounds on the script side, but I was wondering if anyone has a clever way to input a value into the helper column Z ONLY IF the corresponding cell (same row) in column A has a value using spreadsheet formulas.
I suspect that an array formula with a filter might do it, but I have little experience with either and can't get anything to work out.
Thanks for your help!
You can use this expression with INDEX, MAX and ROW to make an ARRAYFORMULA only expandable until the last cell with value in column:
A2:INDEX(A2:A,MAX(ROW(A2:A)*(A2:A<>"")))
It will go from A2 to the maximum number of row in A in which A is different than null (that's why both conditions are multiplied).
Then you can set a formula like this in Z2 (check the ranges in case something is not right from reading your text, and delete all other formulas in Z too in case you weren't using an arrayformula already):
=BYROW(A2:INDEX(A2:A,MAX(ROW(A2:A)*(A2:A<>""))),LAMBDA(each,IF(each="","",COUNTIF('Sheet B'!C:C,each))))

Setting array formula until last column in Google Sheets

I have a formula as follows in google sheets:
=ARRAYFORMULA(IF(LEN(F2:F),IFERROR(SPLIT(REPT("PAID ",F2:F)&REPT("- ",(24-F2:F))," ")),))
This formula will show paid according to number of paid in the cell and show "-" to the cells in the rest column. For now, this formula is only applicable for columns. I dont want like that, I want this formula to be used until the last column because the number of columns will be increased every year. I dont know whether this should be done in Google App Script or what. Anything should be fine to solve my problems. I have attached some images to explain myself clearly. Thanks in advance.
https://docs.google.com/spreadsheets/d/1bM8l6JefFsPrlJnTWf56wOhnuSjdIwg3hMbY1tN1Zp8/edit#gid=1775459006 - Link to google sheets
I will use the sheet "JALAN SANGGUL 4" as an example. Then you will need to apply to all of the other sheets that have the same structure.
Replace your current G1 formula with this:
=TRANSPOSE(FILTER(Configuration!P2:P,Configuration!P2:P<>""))
Replace your current G2 formula with this:
=ARRAYFORMULA(IF(LEN(F2:F),IFERROR(SPLIT(REPT("PAID ",F2:F)&REPT("- ",(COUNTA(FILTER(G1:1,G1:1<>""))-F2:F))," ",1,1)),))
The added FILTER in each constrains things to only areas where data exists. By counting where only data exists instead of using a set "24" in the second REPT clause, you'll always get dashes going only as far as there are months in Row 1.

How to crossmatch data of a column with multiple column and take action if it matched?

Here I have two sheets in google spreadsheet.
Please check the screenshot
I would like to automatically search all the single data of column A of Sheet 2 in Column A and C of Sheet 1 and if it matched it would make the checkboxes ticked on column B and D of sheet 1 and if its not matched it would leave it as it was. I have attached that screenshot which is the result I expect. Is there any functions or script to do this?
I'm not familiar with such staffs. A help would be greatly appreciated.
Thanks
you do not need to write a script for this - an array formula can do it all
to the formula start working - you need to clear out everything from the range B1:B7 . then paste the formula =ArrayFormula(IFNA(VLOOKUP(A1:A7,Sheet2!$A:$A,1,false),)=A1:A7) into cell B1, then select range B1:B7 and paste checkboxes through the menu Insert - Checkbox
the formula for the range D1:D7 is inserted in the same way
=ArrayFormula(IFNA(VLOOKUP(C1:C7,Sheet2!$A:$A,1,false),)=C1:C7)
after some thought, came to the conclusion that the formulas could be much simpler
=ArrayFormula(COUNTIF(Sheet2!$A:$A,A1:A7)>0) for cell B1
=ArrayFormula(COUNTIF(Sheet2!$A:$A,C1:C7)>0) for cell D1

Google Sheets -fill a cell with contents of a different cell when not blank

I am new to Google Sheets. I and am trying to make a spreadsheet where column A has a list of words and when I type an x or something in a cell in a different column (lets say column B)it automatically fills with the word contained in column A in the same row. I have tried to use =IF(CELL(not(empty... with different arguments but I really don't know what I am doing. I'm trying to read up on Google Apps Script and figure out a way to write a macro to accomplish this but again, I'm not sure if I need a macro. I would appreciate any help I can get on this.
The answer above is also correct, alternatively you can use the following formula:
if(B1 <> "",B1, "")
Enter the above formula into cell A1 and drag it down column A as far as it needs to be.
Broken down this says, if B1 is not blank, then make A1 the same as B1, else make A1 blank.
Here is Google Script unnecessary.
Just use Formula. Here you can put to A1:
=B1
and in A1 will be the same word as in B1. If you need condition, try to A1 set:
="My magic word is: " & IF(ISBLANK(B1),"(nothing)",B1)

Excel - Advanced Sorting Function

I have a tournament spreadsheet that has a list of names in column "D" (between 20 and 150 entries) and the table number that each person is assigned to (column "E").
In column "I", I have a ridiculous formula that creates a list of the number of seats available at each table (this information changes from one event to another).
Column "G" is my problem. I want to run through the contents of column "E" and anytime there is a value in column "E" that matches the contents of column "I", to give the the contents of column "D".
Here is my formula as it currently stands in cell G3:
{=IFERROR(INDEX(D$3:D$150,SMALL(IF(E$3:E$150=I3,ROW(E$3:E$150)-ROW(E$3)+1),ROWS(E$3:E3))),"")}
The formula works perfectly for all values in column "E" as long as the value in column "E" is 1. This formula works beautifully in Google Sheets but Excel seems to process the ranges differently. I've tried with both a standard formula and an array formula without success.
Any advice would be greatly appreciated.
One additional note, I can use VBA if needed but I would prefer to stick with functions.
for this example I used the following formula:
=INDEX($C$14:$C$25,AGGREGATE(15,6,(ROW($D$14:$D$25)-ROW($D$14)+1)/($D$14:$D$25=H16),COUNTIF($H$16:H16,H16)),1)
You will need to adjust the ranges to suit your needs.
From my testing, the problem appears to be with the ROWS(E$3:E3) as the second argument for the SMALL function. Basically, when you get down to your first 2 in row 12, you are asking the small function for the 10th smallest value in D that has 2 in column E. Since it looks like you are only expecting eight players, this will never find anything.
Try changing ROWS(E$3:E3) to COUNTIF(I$3:I3, I3).
That will count how many 1's or 2's you've already passed in column I, so when you get to the 2's, it should reset and ask for the first smallest.
#Forward Ed. Thanks for your input. That helped get me on the path that I needed.
Here is the formula that ended up working for me:
{=IFERROR(INDEX(D$3:D$150,SMALL(IF(E$3:E$150=I3,ROW(E$3:E$150)-MIN(ROW(E$3:E$150))+1),J3)),"")}