Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How can I use multiple values to create sheet names when using a script to create multiple sheets from master sheet?

$
0
0

I have a list of students assigned to various test rooms, and each room has a different test. (Although there are duplicates.) I would like to create a separate sheet for each test room where the name of the sheet includes both the test name and room number. I found a Youtube video that showed me how to create a script to make multiple filtered sheets from a master sheet and name each sheet based on the filter criteria. When I used the script for myself I used the room numbers as the filter criteria, but I would like to know how I could adjust the script so that when it is naming each new sheet it includes the test name as well as the room number.

I have tried simply adding a column in the master list that concatenates the desired info and reading from there, and that works, but I am hoping there is a way to do it in the script directly. (That an absolute novice like me can understand, lol.)

Here is the script I have been using (for a similar set of data, but without test name):

function myFunction() {  const ss = SpreadsheetApp.getActiveSpreadsheet();  const sourceWS = ss.getSheetByName ("PSAT9");  const testLocations = sourceWS    .getRange(2, 6, sourceWS.getLastRow()-1,1)    .getValues()    .map(tr => tr[0]);  const uniqueTestLocations = [...new Set(testLocations)];  const currentSheetNames = ss.getSheets().map(s => s.getName());  let was;  uniqueTestLocations.forEach(testRoom => {    if (!currentSheetNames.includes(testRoom)){      ws = null;      ws = ss.insertSheet ();      ws.setName(testRoom);      ws.getRange("A2").setFormula(`=SORT(FILTER(PSAT9!A2:J, PSAT9!F2:F="${testRoom}"),4,1)`);      sourceWS.getRange("A1:J1").copyTo(ws.getRange("A1:J1"));    }  }) }

Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>