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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Shifting rows

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
surjpanj Posted - 03/02/2016 : 07:53:55 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
surjpanj Posted - 03/03/2016 : 05:58:10 AM
Thanks! It works perfectly.

Matt
Hideo Fujii Posted - 03/02/2016 : 1:54:08 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000