Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /**
 * Selects all contacts by checking all boxes and copying rows to the current campaign
 */
function selectAllForCampaign() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const mainSheet = ss.getSheetByName('Customers & Opportunities');
  
  if (!mainSheet) {
    SpreadsheetApp.getUi().alert('The "Customers & Opportunities" sheet could not be found.');
    return;
  }
  
  // Find the NEWCAMPAIGN column
  const headers = mainSheet.getRange("1:1").getValues()[0];
  const checkboxColumnIndex = headers.findIndex(header => header === "NEWCAMPAIGN");
  
  // Determine the last column to copy by finding "--------" in row 1
  const endDataColumnIndex = headers.findIndex(header => header === "--------");
  
  if (checkboxColumnIndex === -1) {
    SpreadsheetApp.getUi().alert('No "NEWCAMPAIGN" column found. Please add "NEWCAMPAIGN" to the header row.');
    return;
  }
  
  if (endDataColumnIndex === -1) {
    SpreadsheetApp.getUi().alert('No "--------" column found. Please add "--------" to the header row.');
    return;
  }
  
  // Check if we have an active campaign created
  const scriptProperties = PropertiesService.getScriptProperties();
  const currentSheetId = scriptProperties.getProperty('currentSheetId');
  
  if (!currentSheetId) {
    SpreadsheetApp.getUi().alert('No campaign sheet is currently active. Please create a new campaign first.');
    return;
  }
  
  // Get the target sheet
  const allSheets = ss.getSheets();
  const targetSheet = allSheets.find(sheet => sheet.getSheetId().toString() === currentSheetId);
  
  if (!targetSheet) {
    SpreadsheetApp.getUi().alert('The target campaign sheet could not be found. Please create a new campaign.');
    return;
  }
  
  // Get all data rows (skipping header row)
  const lastRow = mainSheet.getLastRow();
  if (lastRow <= 1) {
    SpreadsheetApp.getUi().alert('No data found in the sheet.');
    return;
  }
  
  // Get all data from main sheet that needs to be copied
  const dataRange = mainSheet.getRange(2, 1, lastRow - 1, endDataColumnIndex);
  const dataValues = dataRange.getValues();
  
  // Get the range for the checkbox column
  const checkboxRange = mainSheet.getRange(2, checkboxColumnIndex + 1, lastRow - 1, 1);
  
  // Create an array of "true" values to set all checkboxes
  const numRows = lastRow - 1;
  const checkboxValues = Array(numRows).fill([true]);
  
  // Set all checkboxes to checked
  checkboxRange.setValues(checkboxValues);
  
  // Add a "Copied!" note to each checked row
  const notes = Array(numRows).fill(['Copied!']);
  checkboxRange.setNotes(notes);
  
  // Copy all rows to the target sheet
  let rowsAdded = 0;
  for (let i = 0; i < dataValues.length; i++) {
    // Skip rows with no data (completely empty rows)
    if (dataValues[i].some(cell => cell !== '')) {
      targetSheet.appendRow(dataValues[i]);
      rowsAdded++;
    }
  }
  
  // Format and activate the target sheet
  targetSheet.activate();
  
  // Show confirmation
  SpreadsheetApp.getUi().alert('Added ' + rowsAdded + ' contacts to ' + targetSheet.getName() + '.');
}
              
            
!
999px

Console