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 Substitution in Cell Formulas
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

RandomOUser

5 Posts

Posted - 06/15/2020 :  09:14:02 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hey Origin community,

I have a question concerning OriginPro 2020. In order to combine data from multiple workbooks and worksheets into a single sheet for further processing, I use cell formulas to access values.

As an example, I might type =[Book1]Sheet1!B1 into column A1 of a sheet to access cell B1 of Sheet1 in Book1.

In some cases, I would now like to "build" the references to different books and sheets using variables. As an example, I would like to replace Book1 in the aforementioned cell formula with a formula referencing a certain cell containing the corresponding workbook name as a string (let's say B3) in the active sheet. I tried subsituting Book1 with B3$ (obtaining =[B3$]Sheet1!B1 as a cell formula) / $(B3) / %(B3) / =B3$ etc. but nothing seems to work. I guess I don't understand the substitution notation correctly...

Can anyone help me?

Thank you for your help!

Edited by - RandomOUser on 06/15/2020 09:17:06 AM

Chris D

428 Posts

Posted - 06/15/2020 :  09:49:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you assign a global string variable:

string B3$ = "Book1";

try putting this in the cell formulae

=%([B3$]Sheet1, 2, 1)


Reference: https://www.originlab.com/doc/LabTalk/guide/Substitution-Notation#Worksheet_Column_and_Cell_Substitutionsubstitution.2C_worksheet_column.2Fcellworksheet.2C_column_and_cell_substitution

Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

RandomOUser

5 Posts

Posted - 06/15/2020 :  12:24:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
First of all thank you for your help. Doesn't seem to work for some reason. If I enter your formula into an arbitrary cell after having defined the variable through the command window, all commas are replacedc by dots (might this have to do with european decimal point settings?) and I get no return value.

But anyways: If I understand you correctly, there is no way to achieve what I want without first defining a variable? I.e. it is not possible to avoid having to use separate scripts? That would be rather unfortunate because it would defeat the purpose of what I am triying to do. The idea is to extract book and sheet names from cell values without taking the detour of defining a variable.

Thanks again!

Edit: I have played around a bit and it seems that setting the cell formula to =[%(col(B)[3]$)]Sheet1!A1 does the trick.

Edited by - RandomOUser on 06/15/2020 1:07:56 PM
Go to Top of Page

Chris D

428 Posts

Posted - 06/15/2020 :  1:19:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Let's see if I understand it okay.

If this value is in the current worksheet in column B, row 2:

Book3

And I put this cell formula in the same sheet somewhere:

=%([B2$]Sheet1, 2, 1)


It will fill the cell with the value from Book3, Sheet1, column B, row 1.

Is that what you want?

Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

RandomOUser

5 Posts

Posted - 06/15/2020 :  4:21:57 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for your swift reply. Yes, this is exactly what I want to do. However, if I copy and paste =%([B2$]Sheet1, 2, 1)
to an arbitrary cell (of course making sure that the book / sheet / cell referenced actually exist and having the value Book3 in cell B2), I only get an "unknown function" error and the cell contents is automatically changed to =%([B2$]Sheet1. 2. 1) for whatever reason. I use OriginPro 2020 (64-bit) SR1 9.7.0.188 (Academic) on Windows 10, if that helps.
What does work, however, is using =[%(col(B)[2]$)]Sheet1!A1 instead. I have no idea why your code doesn't work. It would be much cleaner than my version.

quote:
Originally posted by Chris D

Let's see if I understand it okay.

If this value is in the current worksheet in column B, row 2:

Book3

And I put this cell formula in the same sheet somewhere:

=%([B2$]Sheet1, 2, 1)


It will fill the cell with the value from Book3, Sheet1, column B, row 1.

Is that what you want?

Thanks,
Chris Drozdowski
Originlab Technical Support



Edited by - RandomOUser on 06/15/2020 4:23:56 PM
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