Get Cell Values using getRange
This post is a corrected post after AI explains the code included in the book “Google Apps Script 101: Building Work Automation For Free”. Added a strikethrough when editing what AI has written, and added color when edited by author
Table of Contents
Summary
In this blog post, we will explore how to access cell values in Apps Script. We will learn how to use the getActiveSheet()
method, the getRange()
method, and the getValues()
method to retrieve the value of a specific cell in a Google Sheets spreadsheet.
Code
1 2 3 4 |
function getD3Value() { const value = SpreadsheetApp.getActiveSheet().getRange(3, 4).getValues(); Logger.log(value); } |
Code Explanation
The code declares a function named getD3Value
. Inside the function, the getActiveSheet()
method is used to get the currently active sheet. The getRange()
method is then called with the parameters 3
and 4
to specify the cell at the third row and fourth column.
The getValues()
method is used to retrieve the value of the specified cell. The value is stored in the value
variable.
Finally, the Logger.log()
method is used to print the value to the Apps Script Logger.
Example
When the getD3Value
function is executed, the value of the cell at the third row and fourth column will be logged in the Apps Script Logger.
1 |
[[Value]] |
AI Prompt
Write a function that retrieves the value of a specific cell in a Google Sheets spreadsheet using Apps Script. Log the value in the Apps Script Logger.