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
 Origin Forum
 using script to add an equation to ws cell
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

zknauss

USA
72 Posts

Posted - 07/13/2022 :  4:42:00 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Using command script I'd like to get the equation below inserted in cell A1 and then have it copied across all columns in row A so that the data sources automatically update (as they would if you manually pulled the equation across. I've tried doing this numerous ways but can't seem to get the equation to be entered into the cell. Thanks!

=Slope([NCONT1PeakDa1]"Center Grvty"!1,[NCONT1PeakDa1]"Peak Index"!1)



ZTK

YimingChen

1649 Posts

Posted - 07/14/2022 :  09:10:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Can you try replacing the column index by column short name?

=Slope([NCONT1PeakDa1]"Center Grvty"!A,[NCONT1PeakDa1]"Peak Index"!A)

See if this works.

James

Edited by - YimingChen on 07/14/2022 09:10:56 AM
Go to Top of Page

zknauss

USA
72 Posts

Posted - 07/14/2022 :  10:43:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It's not so much the equation that is the problem but how to get the equation to pull data correctly for each column I figured out the first part to put the equation in Col:(A) row:(1) below. Now I just need it applied to each column in the spreadsheet so columns A:end. I've also written out what the next column would be if I wrote out the full equation for each column entry

Col(A)=Movslope([NCONT1PeakDat]"Center Grvty"!1,[NCONT1PeakDat]"Peak Index"!1);

Col(B)=Movslope([NCONT1PeakDat]"Center Grvty"!2,[NCONT1PeakDat]"Peak Index"!2);
Go to Top of Page

zknauss

USA
72 Posts

Posted - 07/14/2022 :  11:19:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This is the excel macro version of what I'd like to do.

Range("A1:B1").Select
Selection.AutoFill Destination:=Range("A1:end"), Type:=xlFillDefault

Where Columns 1 and 2 already have the function in row 1 and then that function is copied through the end of the document.

ZTK
Go to Top of Page

YimingChen

1649 Posts

Posted - 07/14/2022 :  11:40:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can just do a for loop:

for (int i = 0; i <= wks.ncols; i++) {
	wcol(i) = movslope([NCONT1PeakDa1]"Center Grvty"!$(i),[NCONT1PeakDa1]"Peak Index"!$(i));
}


James
Go to Top of Page

zknauss

USA
72 Posts

Posted - 07/14/2022 :  12:06:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That worked perfectly just had to add a space after the i++ Thanks so much!

ZTK
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