OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Move a specific cell data in a row from a sheet to another sheet

  • Thread starter Thread starter Leopard
  • Start date Start date
L

Leopard

Guest
I have a source sheet which contains records of employees who borrows company equipment for work. The data on this source sheet (sheet2) contains the data of current user, details of the equipment and dates in row format. For previous user records, it is located just to the right side of the current users. So basically the previous records will show "Previous user 1", Previous user 2" an so on.

In sheet1 which is where I filter the details of the current user base on the unique tag of the equipment. For example in sheet1 in my sample data, I filter out TV-002, I need the name, ID, start date and return date of the equipment, then move these data to the next blank cells in the "Previous Users" range.

Here is a link of my Google sheet screenshots. Sheet screenshots link

Here is my sample Google sheet data

Google Sheets sample data

I am a beginner in app script so I am not sure to do this, since the codes that I have tried will not allow me to put the data on the intended range which is in the previous users part.

This is the code that copied from someone and I tested but its only moving one cell value (B5) to the target sheet and its in the wrong row as well.

Code:
function moveRows(){

    // Start: Get the data to move

        // Get the current sheet object
        var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
        
        // Get the number of the row to move
        var rowToMove = sourceSheet.getRange(5,1,1,1).getRow();
        Logger.log("rowToMove: " + rowToMove);

        // Get the range to move
        var rangeToCopyFrom = sourceSheet.getRange(rowToMove, 2, 1, 1);
    
    // End: Get the data to move

    // Start: Copy and paste the data
    
        // Get the target sheet
        var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
        
        // Get last row in target sheet
        var lastColInTargetSheet = targetSheet.getLastColumn();
        Logger.log("lastColInTargetSheet: " + lastColInTargetSheet);
        
        // Get range to paste to
        var rangeToPasteTo = targetSheet.getRange(lastColInTargetSheet + 1, 1, 1, 1);
        
        // Copy and paste the data
        rangeToCopyFrom.copyTo(rangeToPasteTo, {contentsOnly:true});
    
    // End: Copy and paste the data

}; // End: moveRows

Continue reading...
 

Latest posts

A
Replies
0
Views
1
Ashrik Ahamed
A
A
Replies
0
Views
1
Ashrik Ahamed
A

Online statistics

Members online
1
Guests online
4
Total visitors
5
Top