The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Shifting rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

surjpanj

Canada
18 Posts

Posted - 03/02/2016 :  07:53:55 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2015
Operating System: Win 7

Hi,

I have many woorksheets each consisting 1000 rows of data. The last 333 rows (i.e., from 667 to 1000) I would like to shift before the first row. What kind of script would automate this?

Thanks,
Matt

Hideo Fujii

USA
1582 Posts

Posted - 03/02/2016 :  1:54:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Matt,

Please try the following function:
////////////////////////////////////////////////////////////////
function double moverows(double rFrom, double rTo, double Dest) {
  nr=wks.maxRows;
  if((rFrom<=Dest && Dest<=rTo) || nr<Dest-1 || Dest<=0) {
    type -b Invalid range;
    Return -1;
  }
  worksheet -a 1;  //add the key column
  nc=wks.nCols;
  if(Dest>rTo) {
    for(ii=1;ii<=nr;ii++) {
      if(ii<rFrom || ii>=Dest)      wcol(nc)[ii]=ii;
      else if(rFrom<=ii && ii<=rTo) wcol(nc)[ii]=ii+Dest-rTo-1; //when from<=ii<=To
      else                          wcol(nc)[ii]=ii-rFrom;      //when To<ii<=Dest
    }
  }
  if(Dest<rFrom) {
    for(ii=1;ii<=nr;ii++) {
      if(ii<Dest || ii>rTo)         wcol(nc)[ii]=ii;
      else if(rFrom<=ii && ii<=rTo) wcol(nc)[ii]=ii+Dest-rFrom; //when from<=ii<=To
      else                          wcol(nc)[ii]=ii-rFrom+rTo+1;  //when Dest<=ii<From
    }
  }
  wsort bycol:=$(nc) descending:=0;  //sort worksheet
  delete wcol(nc);  //delete the key column
  Return 1;
}
////////////////////////////////////////////////////////////////
To execute this function, you can, for example, issue the following call with three argument - From, To, and Destination:
moverows 667,1000,1;

Hope this works.

--Hideo Fujii
OriginLab
Go to Top of Page

surjpanj

Canada
18 Posts

Posted - 03/03/2016 :  05:58:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks! It works perfectly.

Matt
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000