+ Reply to Thread
Results 1 to 4 of 4

Move Rows to top of another sheet

  1. #1
    Registered User
    Join Date
    12-05-2019
    Location
    USA
    MS-Off Ver
    Google Sheets & MS Office
    Posts
    2

    Move Rows to top of another sheet

    Hi,

    I have a script to move rows when a box is checked to another sheet. Currently it will move it to the next sheet and next available row down. Is there a way to write it to always move the row to a certain row in the other sheet? Here is my script. I would like the rows, when checked, to move to the top of the page instead of the bottom. I have the first three rows frozen so I would need it to move to row 4.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 12-31-2019 at 02:51 PM. Reason: Added required CODE tags as per FORUM RULES, please take a moment to read them (link above in menu bar)

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Move Rows to top of another sheet

    This code moves row 8 to Row 4 on Sheet 2
    All the existing rows are moved down
    Then the original Row 8 is deleted.


    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    12-05-2019
    Location
    USA
    MS-Off Ver
    Google Sheets & MS Office
    Posts
    2

    Re: Move Rows to top of another sheet

    I'm sorry but I am new to writing script. Where do I insert this code to make this work? Thanks

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Move Rows to top of another sheet

    I cannot really help you with that.

    I do not understand what your code is doing.


    try
    PHP Code: 
    function onEdit(event) {
      
    // assumes source data in sheet named main
      // target sheet of move to named Completed
      // getColumn with check-boxes is currently set to column 18 or R
      
    var ss SpreadsheetApp.getActiveSpreadsheet();
      var 
    event.source.getActiveSheet();
      var 
    event.source.getActiveRange();

      if(
    s.getName() == "WIP" && r.getColumn() == 18 && r.getValue() == true) {
        var 
    row r.getRow();
        var 
    numColumns s.getLastColumn();
        var 
    targetSheet ss.getSheetByName("Completed");
        var 
    target targetSheet.Row(4);
        
    s.getRange(row11numColumns).moveTo(target);
        
    s.deleteRow(row);
      } else if(
    s.getName() == "Completed" && r.getColumn() == 18 && r.getValue() == false) {
        var 
    row r.getRow();
        var 
    numColumns s.getLastColumn();
        var 
    targetSheet ss.getSheetByName("WIP");
        var 
    target targetSheet.getRange(targetSheet.getLastRow() + 11);
       var 
    targetSheet.InsertRow(4)
        
    s.getRange(row11numColumns).moveTo(target);
        
    s.deleteRow(row);
      }
      

    Last edited by davesexcel; 01-04-2020 at 05:58 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Formula or Macro to Move Rows From Sheet 1 to Sheet 2 in Same Workbook
    By singerr45 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-03-2017, 02:31 PM
  2. [SOLVED] Macros To Move Multiple Rows To Another Sheet And Macro To Move Single Rows To DAX Table
    By jcaynes in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-22-2013, 05:08 PM
  3. Replies: 2
    Last Post: 08-27-2013, 05:01 PM
  4. VBA CODE to move rows from one sheet(1) to another sheet(2) based on data in cell
    By fozzieulo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 02:43 PM
  5. [SOLVED] Move rows of data from one sheet to another based on specific values of sheet
    By buntalan80 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-26-2013, 06:21 AM
  6. [SOLVED] Copy row from sheet 1 to next row in sheet 2. delete from sheet 1 and move rows up
    By papabob1954 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-16-2012, 09:38 PM
  7. Macro to move rows from one sheet to another sheet based on a cell vaule
    By d55272 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-09-2012, 03:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1