What's new

Help Google Sheet App Script. Copy specific Column from sheet 1 to sheet 2

sweetfairy14

Honorary Poster
Established
Joined
Oct 25, 2020
Posts
265
Solutions
1
Reaction
73
Points
166
I'm doing something in Google Sheet. I want to transfer specific data from sheet 1 to sheet 2 using App Script. The problem is I can copy the data from specific column, but it wasn't aligned to the specific data. I want to align them but when I add data it will add at the bottom part of the column.


Ito po yung sample. Hindi po siya align :< patulong naman po.

1682489010395.png
 

Attachments

Hello! It sounds like you want to copy specific data from one column in sheet 1 to another column in sheet 2, but you want the data to be aligned to the specific data in sheet 1.

To achieve this, you can use the getValues() method to retrieve the data from sheet 1, and then loop through the data to find the specific data you want to copy over. Once you've found the specific data, you can use the setValue() method to add it to the corresponding row in sheet 2.

Here's some sample code that you can use as a starting point:

Code:
function copyData() {
  var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
  var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
  
  // Get all the data from column A in sheet 1
  var data = sheet1.getRange("A:A").getValues();
  
  // Loop through the data to find the specific data you want to copy
  for (var i = 0; i < data.length; i++) {
    if (data[i][0] == "Specific Data") { // Replace "Specific Data" with the data you want to copy
      // Copy the data to the corresponding row in column A in sheet 2
      sheet2.getRange(i+1, 1).setValue(data[i][0]);
    }
  }
}

In this example, the code copies the data from column A in sheet 1 to column A in sheet 2. If you want to copy the data to a different column in sheet 2, you'll need to change the getRange() and setValue() methods accordingly.

I hope this helps! Let me know if you have any other questions.
 

Similar threads

Back
Top