I want to customize my Google Apps Script to only target specific cells, not all cells

I need help with a script that changes the currency symbol within specific cells based on user selection. Currently, the script is applied to all cells but I only want it to affect cells C9, C12, and C13. I'm not sure where to make this adjustment in the script. Any guidance would be appreciated!

function udtsymbol () {
    const s = SpreadsheetApp.getActiveSheet();
  const r = s.getDataRange();
  const symb = {"$":"$", "€":"€", "£":"£"};
  r.setNumberFormat(symb[s.getRange("C8").getValue()]+"###,##0.00");

I've tried modifying the code by adding ranges or using if statements, but I keep encountering errors as I am not familiar with JavaScript. After researching for hours, I decided to seek assistance here.

Answer №1

Regarding the request to apply changes only to cells C9, C12, and C13 in this particular scenario, it might be beneficial to utilize RangeList as shown below:

From:

const range = sheet.getDataRange();

To:

const range = sheet.getRangeList(["C9", "C12", "C13"]);
  • With this adjustment, any updates made using setNumberFormat will now affect the specified cells: ["C9", "C12", "C13"].

Reference:

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

What is the method for accessing JSON data?

Looking for assistance on a coding issue I'm facing. I need my JavaScript code to read JSON data and grant access to a staff panel based on the information provided. Below is the sample JSON: { "User1": { "User": " ...

Receiving blank response when trying to access server variable on the client side

Query: On the server side, I set the value of SessionData(EmployeeID) = "12345", which is first executed during page_load. Later, on the client side: function getEmployeeId() { return "<%# SessionData("EmployeeID")%>"; } When I use th ...

Implementing multiple dropdown menus with Material UI in a navigation bar

I am currently working on designing a navigation bar that consists of multiple material UI dropdown menus. However, I have encountered an issue that has proven to be quite challenging for me to resolve. Whenever I click on a navigation bar item, all the dr ...

Incorporate a new item into an array within DynamoDB that does not currently

I am attempting to update an attribute called items, which is a list of strings. Is it possible to update (append) the attribute only if it does not already exist? Something like a combination of list_append and if_not_exists. var params = { ... Upda ...

c# server-side method is failing to execute when called from an AJAX request in ASP.NET

I am attempting to utilize ajax to call a C# method in the following manner. <a href="#divrecentQ" id="linkdivrecentQ" onclick="lnkClick();" aria-controls="divrecentQ" role="tab" data-toggle="tab&qu ...

Are you looking for JavaScript templating that also includes internationalization support? If so, what else are you searching

In the foreseeable future, I envision the distribution of my multilingual single-page-application. This application will house an array of resources such as videos, texts, and interactive applications for both web and desktop usage (including offline acces ...

Attaching to directive parameters

I've been working on creating a draggable div with the ability to bind its location for further use. I'm aiming to have multiple draggable elements on the page. Currently, I've implemented a 'dragable' attribute directive that allo ...

Is there a JavaScript syntax highlighter out there that offers compact size and stylish design?

After testing what appears to be the most commonly used syntax highlighter, I found that the file size is quite large and it seems a bit cumbersome to include. Additionally, I personally find the format of the highlighted code to be unappealing. Are there ...

The issue with Angular's state.go function is that it is not properly refreshing the page, resulting in

Creating a mobile exam app that features multiple choice questions with previous and next question buttons. The transition between questions is handled using $state.go to load the same HTML page but with new questions and answer choices. // Within a servi ...

Get the Best Width for CSS3 Printing

After running my code to window print the table (report), the output is displayed below: https://i.sstatic.net/chZ2b.png This is the code I used: CSS @media print { body * { visibility: hidden; } #reportArea, #reportArea * { visibility: ...

What modifications can I make to my JavaScript code in order to enable clicking through an HTML list?

I'm facing an issue with getting my list to function properly. I want users to be able to navigate through the list by clicking on next and previous buttons, but for some reason, the code is not working as expected. When they click next, the next item ...

Active tab in HTML

In my implementation based on this example code from https://www.w3schools.com/howto/howto_js_tabs.asp, I have a specific requirement. I want the tab for "Paris" to remain active even after the page is refreshed if the user has clicked on the button for "P ...

Swapping out the context of JavaScript's this keyword

After researching scope and context through various articles, I still have a question lingering in my mind. If you take a look at my JSFiddle here, you'll see what I'm working with. My goal is to convert my functions to arrow functions and replac ...

Manipulate paths in JS/JQuery by dynamically adding parameters with an indefinite number of values

My JavaScript script relies on an AJAX call that adds a parameter to an HTML request, but I've encountered two issues. I'm struggling to find a straightforward method to retrieve the pathname with parameters. With pure JavaScript, location.path ...

Troubleshooting FileReader.onload Failure Following Form Submission (POST) in JavaScript

Currently, I am in the process of developing a single-page uploader using Javascript (+jQuery) and leveraging AppJS. This uploader consists of two forms with upload inputs. Both forms are on the same page, with the second form initially hidden using displ ...

Tips for Removing Numbers from a Doughnut Chart in ChartJs 2 upon Initialization

I am currently struggling with a doughnut chart that is displaying data numbers on the chart segments upon loading, making it appear cluttered. I have attempted to remove these labels using the following code: Chart.defaults.global.legend.display = false; ...

Tips for Isolating and Manipulating a Single Element in Array.map() with REACT.JS

Is there a way to change the style of a specific element in an array without affecting others when a button is clicked? I've been struggling with this because every time I try, it ends up changing all elements instead of just the one that was clicked. ...

I am facing an issue in JavaScript where one of my two timers is malfunctioning

While working on my tank game, similar to Awesome Tanks, I encountered an issue with the AI tank shooting mechanic. I set up a separate timer for the AI tank to shoot a bullet, but when I attempt to run it, I receive an error stating that AItimer is not de ...

Is it possible for my website to send an email without the need for a script to be executed?

Looking to include a contact page on my website, but struggling with limitations imposed due to hosting on a secure school server that restricts script execution. Wondering if there's a workaround that would allow for email sending on the client side ...

Click event triggers dynamic function call

Is it possible to have different functions for ng-click depending on the loaded controller page? <a ng-click="removeEvent(event)" class="top_menu_link"> REMOVE</a> For instance, if I want the same button to trigger a remove action but on diff ...