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

Status
Not open for further replies.

PHC - SweetFairy

Eternal Poster
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.webp
 
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.
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 515
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,063
Guests online
1,394
Total visitors
2,457

Forum statistics

Threads
2,273,400
Posts
28,949,274
Members
1,235,735
Latest member
rutlas
Back
Top