{"id":15436,"date":"2023-08-01T09:00:00","date_gmt":"2023-08-01T00:00:00","guid":{"rendered":"https:\/\/www.autooffice.co.kr\/blog\/2023\/08\/01\/fetching-values-from-a1c3-for-multiple-sheets-in-apps-script\/"},"modified":"2025-09-15T18:36:45","modified_gmt":"2025-09-15T09:36:45","slug":"fetching-values-from-a1c3-for-multiple-sheets-in-apps-script","status":"publish","type":"post","link":"https:\/\/www.autooffice.co.kr\/en\/blog\/2023\/08\/01\/fetching-values-from-a1c3-for-multiple-sheets-in-apps-script\/","title":{"rendered":"Fetching Values from A1:C3 for Multiple Sheets using for Iteration"},"content":{"rendered":"<p>This post is a corrected post after AI explains the code included in the book <a href=\"https:\/\/www.autooffice.io\/content\/ebizbooks-apps-script\" target=\"_blank\" rel=\"noopener\" title=\"\">&#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>In this blog post, we will explore how to fetch values from the range A1:C3 for multiple sheets in Apps Script. We will use a loop to iterate through a list of sheet names, access each sheet by name, and retrieve the values from the specified range.<\/p>\n<h2 id=\"code\">Code<\/h2>\n<pre><code>function getA1C3ValuesForIteration() {\n  const SS = SpreadsheetApp.getActiveSpreadsheet()\n  const sheetNames = ['Sheet1', 'Sheet2']\n\n  for (let i = 0; i &lt; sheetNames.length; i++) {\n    const sheet = SS.getSheetByName(sheetNames[i])\n    const value = sheet.getRange('A1:C3').getValues()\n    Logger.log(value)\n  }\n}<\/code><\/pre>\n<h2 id=\"explanation\">Code Explanation<\/h2>\n<p>The code defines a function named <code>getA1C3ValuesForIteration<\/code>. It first gets the active spreadsheet using <code>SpreadsheetApp.getActiveSpreadsheet()<\/code>. The variable <code>sheetNames<\/code> is an array that stores the names of the sheets we want to fetch values from.<\/p>\n<p>A <code>for<\/code> loop is used to iterate through each sheet name. Inside the loop, the <code>getSheetByName()<\/code> method is used to retrieve the sheet object based on the name. Then, the <code>getRange()<\/code> method is used to specify the range A1:C3, and the <code>getValues()<\/code> method is used to retrieve the values within that range as a 2D array.<\/p>\n<p>The retrieved values are logged using <code>Logger.log()<\/code>.<\/p>\n<h2 id=\"example\">Example<\/h2>\n<p>When you run the <code>getA1C3ValuesForIteration<\/code> function, it will fetch the values from the range A1:C3 for each sheet specified in the <code>sheetNames<\/code> array. The retrieved values will be logged in the Apps Script Logger.<\/p>\n<h2 id=\"ai-prompt\">AI Prompt<\/h2>\n<p>Write a function that fetches values from the range A1:C3 for multiple sheets in Apps Script. Use a loop to iterate through an array of sheet names, access each sheet by name, and retrieve the values from the specified range. Log the retrieved values.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post, we will explore how to fetch values from the range A1:C3 for multiple sheets in Apps Script. We will use a loop to iterate through a list of sheet names, access each sheet by name, and retrieve the values from the specified range.<\/p>\n","protected":false},"author":1,"featured_media":15448,"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,527,526,7],"class_list":["post-15436","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spreadsheet","category-apps-script","tag-ai-assisted","tag-script","tag-for","tag-getsheetbyname","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\/15436","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=15436"}],"version-history":[{"count":3,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts\/15436\/revisions"}],"predecessor-version":[{"id":17224,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts\/15436\/revisions\/17224"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/media\/15448"}],"wp:attachment":[{"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/media?parent=15436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/categories?post=15436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/tags?post=15436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}