Microsoft Excel Scripts uses typescript to allow you to automate repetitive tasks in Excel which saves your time and effort. In this article, we'll give you a few code snipts to do the basic tasks using excel scripts.
1. Copy data from one cell to another
This is one of the most used functionalities in excel. Use the code below to automate that using excel scripts.
function copyCell() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var source = sheet.getRange("A1");
var destination = sheet.getRange("B1");
source.copyTo(destination);
}
2. Change cell color
Excel Scripts can also automate the process of changing cell color, making it easy to change the color of multiple cells simultaneously. See sample code which does that.
function changeColor() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getRange("A1");
cell.setBackground("#f0f8ff");
}
3. Change font
We change fonts in our workbooks for many reasons. If you need to automate that using excel scripts here is the sample code.
function changeFont() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getRange("A1");
cell.setFontFamily("Arial");
}
4. Change font color
Again, changing font color is a must do when we develop a dashboard, reports, etc. in excel. See how we could do this.
function changeFontColor() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getRange("A1");
cell.setFontColor("#000000");
}
No comments:
Post a Comment