cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Help!Can't use WRITEEXCEL function in for-loop

ptc-6390704
1-Newbie

Help!Can't use WRITEEXCEL function in for-loop

My Worksheet is like this:

test.png

I get two matrix:A and B.

A contains some numbers.B contains some strings that indicate certain blank which numbers in A should be put into.For example,A_1,3=0.009,so 0.009 should be put into Sheet1!G10(=B_1,3) in test.xlsx.

I use WRITEEXCEL function to achieve the goal but find it didn't run in for-loop.I still try other write-file functions such like WRITETEXT in for-loop and find none of them work.

Is it a bug?

Any one can help?

PS: I use Mathcad Prime 3.0 F000

PS:ORIGIN=1

1 ACCEPTED SOLUTION

Accepted Solutions

Haven't started up Prime but I guess your loop is not executed because the program sequence is not evaluated or assigned. So assign the sequence to a dummy variable like dummy:=for.... or add an evaluation = after the seqeunce.

An even better and more versatile idea would be to turn the sequence into a function in A and B.

View solution in original post

5 REPLIES 5

Haven't started up Prime but I guess your loop is not executed because the program sequence is not evaluated or assigned. So assign the sequence to a dummy variable like dummy:=for.... or add an evaluation = after the seqeunce.

An even better and more versatile idea would be to turn the sequence into a function in A and B.

So much thanks!!!

Your answer is quite useful.

Excuse me,I am a newbie.Could you explain how to turn the sequence into a function in A and B?

Sherwin Zhang wrote:

So much thanks!!!

Your answer is quite useful.

Excuse me,I am a newbie.Could you explain how to turn the sequence into a function in A and B?

You simply define

Write(A,B):=for.....

and Write is an arbitrary name of your choice.

Later, wehn you want to use/call that function use something like

dummy:=Write(X,Y) // remark: you can use variable names A and B, but you must not

or

Write(X,Y)=

Maybe even better to make the file name a function argument and maybe even the name of the sheet (it must exist!). See attached file.

What exactly are you trying to do? You are aware that using WRITEEXCEL you may not only write one cell at at time but a whole rectangular matrix of values?

Thank for your valuable reply.

What I want to do is to put data in certain blanks.Normally we can use WRITEEXCEL to write a whole rectangular matrix of values,but sometimes we have to put one value in a blank and another value in other blank which location have no relation to the previous one in order to cooperate with other software that give the location.

Sherwin Zhang wrote:

Thank for your valuable reply.

What I want to do is to put data in certain blanks.Normally we can use WRITEEXCEL to write a whole rectangular matrix of values,but sometimes we have to put one value in a blank and another value in other blank which location have no relation to the previous one in order to cooperate with other software that give the location.

OK, I just was concerned because your test sheet creates a continuous rectangular matrix of values in Excel which could have been achieved in a simpler way.

Top Tags