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
 script to copy and paste from subset of 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

wmfry

Canada
Posts

Posted - 01/03/2011 :  7:51:18 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi
I'd appreciate some help in writing a script. Consider two worksheets, the second contains data for only a subset of rows of the first. How do I make origin paste the data from the second worksheet into the corresponding rows of the first worksheet?

I hope the following example using a registration list and exam for a course will help:


Consider the Registration sheet for september
A(x) b(y)
Name student #
Anne 101
Bill 128
Charlie 178
Dawn 155
evan 103
Frank 190


now imagine charlie drops the course before the midterm. the data set with the midterm marks look like this.

A(x) b(y) c(y)
Name student # midterm mark (/50)
Anne 101 33
Bill 128 20
Dawn 155 40
evan 103 35
Frank 190 38

I'd like to paste the marks (column C) from the above spreadsheet into the first, but it is missing the row for charlie, and manual intervention is required to correctly associate each student with their midterm mark.

How do i make origin pick each student's midterm data from column c(midterm mark) of the second worksheet and correctly paste it into the first worksheet? the end result will have an empty cell for charlie's midterm.

I apologize if my explaination is not clear.

thanks
Mark Fry






Origin Ver. and Service Release 8e
Operating System: XP Pro

Sam Fang

293 Posts

Posted - 01/04/2011 :  03:26:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
In Origin8, you can use X-Function vfind to find the row number in the first worksheet corresponding to cells of the second worksheet. For your example, suppose that the first worksheet is in Book1, second is in Book2, script can be as follows.

range r1=[Book1]1!;
r1.ncols=r1.ncols+1;
range r2b=[Book2]1!col(B);
nr=r2b.GetSize();
range r1b=[Book1]1!col(B);
range r1c=[Book1]1!col(3);
range r2c=[Book2]1!col(C);

for( i=1; i<= nr; i++)
{
  vfind ix:=r1b value:=r2b[i] ox:=vr;
  ir=vr[1];
  r1c[ir]=r2c[i];
}


Sam
OriginLab Technical Services

Edited by - Sam Fang on 01/04/2011 03:31:55 AM
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