Tips for Choosing Specific Ranges in Your Findings

Can data retrieval be customized to show only specific columns based on preferences, such as 1, 5, 8, 11, and 23?

function enterRepName(){

 var ui = SpreadsheetApp.getUi();
 var input = ui.prompt("Please enter your rep name.",ui.ButtonSet.OK_CANCEL);

if(input.getSelectedButton() == ui.Button.OK){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ws = ss.getSheetByName("Monitoring (Database)");
  var data = ws.getRange("A2:X" + ws.getLastRow()).getValues();
  var userSelectedRep = input.getResponseText();
  var filteredData = data.filter(function(row){ return row[23] == userSelectedRep});
  var newWs = ss.insertSheet(userSelectedRep);
  newWs.getRange(2, 1, newData.length, newData[0].length).setValues(filteredData);


}

I attempted using getRangeList without success. Unsure of feasibility, I'm a beginner experimenting with scripts in Google Sheets.

Answer №1

Instead of using getRangeList, you have the option to manually filter the columns by selecting only the ones you need (1, 5, 8, 11, and 23).

function displayInputForm() {
  var ui = SpreadsheetApp.getUi();
  var userInput = ui.prompt("Enter your representative's name", ui.ButtonSet.OK_CANCEL);

  if (userInput.getSelectedButton() == ui.Button.OK) {
    var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
    var worksheet = spreadsheet.getSheetByName("Monitoring (Database)");
    var inputData = worksheet.getRange("A2:X" + worksheet.getLastRow()).getValues();
    var selectedRep = userInput.getResponseText();

    // Filter data based on rep name in column 24 (23 in zero-index)
    var filteredData = inputData.filter(function (row) { return row[23] == selectedRep });

    // Extract specified columns: 1, 5, 8, 11, and 23
    var extractedColumns = filteredData.map(function (row) {
      return [row[0], row[4], row[7], row[10], row[22]];
    });

    // Create a new sheet and populate with selected data
    var newWorksheet = spreadsheet.insertSheet(selectedRep);
    newWorksheet.getRange(2, 1, extractedColumns.length, extractedColumns[0].length).setValues(extractedColumns);
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

php json with multiple dimensions

Unable to retrieve the deepest values from my json object, which contains an array of images listed as: { "imgs":[ { "Landscape":{ "2":"DSCF2719.jpg", "3":"DSCF2775.jpg", "4":"IMG_1586.jpg", ...

How can I display SQL results in a Jade page using Node, Express, and MySQL?

My application built with Node.js and Express is connected to a MySQL database for monitoring purposes. The code structure is as follows: In the Node file: app.get('/banners', function(req,res){ connection.query("SELECT * FROM banner_store_ ...

Whenever there is a click event triggered within the map function, it will affect every element within the collection

I am struggling to make changes to a specific item in the map function when clicked. Can someone assist me with achieving this functionality? const Product = ({categories}) => { const [active,setActive] = useState(true) function activeCat ...

Creating a JSON File with an Illustrator Script

Currently, I've been working diligently on developing a system that allows me to export my swatches from Illustrator as a JSON object. This will greatly simplify the process of updating my App. By utilizing the illustrator scripting API, I've suc ...

Next.js version 13 is causing the page to refresh each time the router is pushed

I am currently developing a search application using NextJs 13, and I have encountered an issue where the page refreshes every time I click the search button. Strangely, this only happens when the application is deployed on Vercel. When running the app l ...

Leveraging the power of JavaScript and jQuery to identify comparable SELECT choices

My current approach involves utilizing the .filter() method to match the value of an INPUT field (prjName) with an option in a SELECT field (prjList). However, this method only works when there is an exact match for the option text: $("select[title=' ...

Having trouble getting the swiping feature to function on jQuery mobile

Hey there, I'm new to this so please bear with me if I'm not getting everything right with posting... I've been trying to figure out how to swipe left and right for jquery mobile by visiting a few pages. I found this page for my script - - ...

Enter the specified text in the input field

My challenge involves dynamically changing a string value that needs to be inserted into an input field. (async () => { let index = 1004327; let browser = await puppeteer.launch({ headless: true, }); let page = await browser.newPage(); ...

How can tick values be displayed on a c3js line chart when all data is unselected?

I'm currently working with a c3js line chart that displays 3 different lines. However, I noticed that when I remove all data sources, the x-axis tick values disappear. Is there a way to keep the x-axis tick values visible even when there is no data pr ...

What is the best way to extract function bodies from a string with JavaScript?

I am currently searching for a solution to extract the body of a function declaration by its name from a JavaScript code string within a Node.js environment. Let's assume we have a file named spaghetti.js that can be read into a string. const allJs = ...

AngularJS requires that JSON object property values be converted to strings in order to be displayed as actual templates

Each tab click accesses a json array containing unique templates such as ui-grid or c3 chart directive (c3.js). When a specific tab is clicked, the template in string format must be rendered into actual templates like ui-grid, c3-chart, etc. var sampleJs ...

The universal CSS variables of Material UI

Creating reusable CSS variables for components can greatly simplify styling. In regular CSS, you would declare them like this: :root { --box-shadow: 0 2px 5px -1px rgba(0, 0, 0, 0.3); } This variable can then be utilized as shown below: .my-class { ...

What is preventing my Button's onClick() method from being effective?

Below is a snippet of my HTML layout using the sciter framework: <div id="volume_micphone_slider" style="z-index:1;"> <input id="volume_slider" class="volume_slider" type="vslider" name="p1c" max="100" value="20" buddy="p1c-buddy" /> < ...

Using JavaScript, adding an element to an array results in the array returning a value of 1

When I try to push a string into an array and then return the array, I am getting unexpected result of "1". Upon closer inspection, it seems that the array is being successfully created but before returning it, only "1" is being returned. Here is the snip ...

Use the knockout textInput plugin in combination with the maskedinput plugin

Is there a simple way to use data-bind="textInput: aProperty" and apply an input mask or automatic formatting while the user is typing? Although using the masked input plugin somewhat works, it results in losing the real-time updates that Knockout's ...

Converting "require" to ES6 "import/export" syntax for Node modules

Looking to utilize the pokedex-promise for a pokemonapi, however, the documentation only provides examples on how to require it in vanilla JavaScript: npm install pokedex-promise-v2 --save var Pokedex = require('pokedex-promise-v2'); var P = new ...

What is the process for extracting image data from a fancybox gallery image when it is clicked?

I successfully implemented a gallery using fancybox. The gallery includes dynamically generated titles, and I am currently working on retrieving the URL of a clicked image and accessing a hidden input value containing the post's URL. Below is the co ...

Issue with running JavaScript functions on HTML elements in a partial when updating it with AJAX in ASP.NET MVC Core

My asp.net mvc core 2.2 application includes a page where a partial is loaded: <div class="col-md-9" id="content"> @await Html.PartialAsync("_TrainingContent") </div> The partial contains a model and loads a video using the video.js playe ...

Leveraging a function for filtering in AngularJS

I have developed an application where the content filter changes depending on which button is clicked. I have managed to figure out the straightforward filters, but now I am attempting to create a filter that displays content within a specified range. Bel ...

``It seems like there was an error with WebComponents and NextJS - the hydration failed due to a mismatch between the initial UI and what was rendered on

I'm running into an issue with the following error message: Error: The initial UI doesn't match what was rendered on the server, leading to hydration failure. This problem occurs when I have a NextJS webpage that includes StencilJS web compone ...