{"id":15404,"date":"2023-07-31T09:00:00","date_gmt":"2023-07-31T00:00:00","guid":{"rendered":"https:\/\/www.autooffice.co.kr\/blog\/2023\/07\/31\/accessing-values-from-range-a1c3-in-apps-script\/"},"modified":"2025-09-15T18:33:42","modified_gmt":"2025-09-15T09:33:42","slug":"accessing-values-from-range-a1c3-in-apps-script","status":"publish","type":"post","link":"https:\/\/www.autooffice.co.kr\/en\/blog\/2023\/07\/31\/accessing-values-from-range-a1c3-in-apps-script\/","title":{"rendered":"Create an array of tab names and use getSheetByName"},"content":{"rendered":"<p>This post is a corrected post after AI explains the code included in the book <a title=\"\" href=\"https:\/\/www.autooffice.io\/content\/ebizbooks-apps-script\" target=\"_blank\" rel=\"noopener\">&#8220;Google Apps Script 101: Building Work Automation For Free&#8221;<\/a>. Added a <s>strikethrough<\/s> when editing what AI has written, and added <span style=\"color: #ff3366;\">color<\/span> when edited by author<\/p>\n<h2>Table of Contents<\/h2>\n<ol>\n<li><a href=\"#summary\">Summary<\/a><\/li>\n<li><a href=\"#code\">Code<\/a><\/li>\n<li><a href=\"#explanation\">Code Explanation<\/a><\/li>\n<li><a href=\"#example\">Example<\/a><\/li>\n<li><a href=\"#ai-prompt\">AI Prompt<\/a><\/li>\n<\/ol>\n<h2 id=\"summary\">Summary<\/h2>\n<p><s>In this blog post, we will explore how to access values from a specific range (A1:C3) in Apps Script. We will use the SpreadsheetApp class to get the active spreadsheet, retrieve a specific sheet, and access the values within the defined range. The retrieved values will be logged using the Logger class.<\/s><\/p>\n<p><span style=\"color: #ff3366;\">Let&#8217;s see how to create an array called sheetNames with the names of the tabs, specify an element of the array to get the tabs, and check the value of the cell.<\/span><\/p>\n<h2 id=\"code\">Code<\/h2>\n<pre><code>function getA1C3Values_3() {\n  const SS = SpreadsheetApp.getActiveSpreadsheet()\n  const sheetNames = ['Sheet1', 'Sheet2']\n  const T_SHEET2 = SS.getSheetByName(sheetNames[1])\n  const value = T_SHEET2.getRange('A1:C3').getValues()\n  Logger.log(value)\n}<\/code><\/pre>\n<h2 id=\"explanation\">Code Explanation<\/h2>\n<p>The code defines a function named <code>getA1C3Values_3<\/code>. Within the function, it retrieves the active spreadsheet using <code>SpreadsheetApp.getActiveSpreadsheet()<\/code>. It also declares an array <code>sheetNames<\/code> containing the names of the sheets in the spreadsheet.<\/p>\n<p>The code then uses the <code>getSheetByName<\/code> method to retrieve the second sheet (index 1) from the active spreadsheet and assigns it to the constant <code>T_SHEET2<\/code>. Next, it uses the <code>getRange<\/code> method to specify the range <code>A1:C3<\/code> within the sheet.<\/p>\n<p>Finally, the code calls the <code>getValues<\/code> method on the range to retrieve the values and assigns them to the constant <code>value<\/code>. The values are then logged using the <code>Logger.log<\/code> method.<\/p>\n<h2 id=\"example\">Example<\/h2>\n<p>When the <code>getA1C3Values_3<\/code> function is executed, the values within the range <code>A1:C3<\/code> from the second sheet of the active spreadsheet will be logged in the Apps Script Logger.<\/p>\n<h2 id=\"ai-prompt\">AI Prompt<\/h2>\n<p>Write a function that retrieves the values from the range <code>A1:C3<\/code> of the second sheet in the active spreadsheet using Apps Script. Log the values using the Logger class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post, we will explore how to access values from a specific range (A1:C3) in Apps Script. We will use the SpreadsheetApp class to get the active spreadsheet, retrieve a specific sheet, and access the values within the defined range. The retrieved values will be logged using the Logger class.<\/p>\n","protected":false},"author":1,"featured_media":15424,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[5,118],"tags":[512,69,7],"class_list":["post-15404","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spreadsheet","category-apps-script","tag-ai-assisted","tag-script","tag-spreadsheet"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"en","enabled_languages":["ko","en"],"languages":{"ko":{"title":true,"content":true,"excerpt":true},"en":{"title":true,"content":true,"excerpt":true}}},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts\/15404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/comments?post=15404"}],"version-history":[{"count":4,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts\/15404\/revisions"}],"predecessor-version":[{"id":17220,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts\/15404\/revisions\/17220"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/media\/15424"}],"wp:attachment":[{"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/media?parent=15404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/categories?post=15404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/tags?post=15404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}