1

Here is original article: link.

Now my question:

Using the .formula, I can get very far, but I have a very complicated formula and it doesn't want to work.

The code that works in Excel:

=IF(ISBLANK(G2),"",VLOOKUP("*"&LEFT(G2,9)&"*",'\\compname\path\to\excel\[ramdata.xlsx]20151009'!A:B,2,FALSE))

The code that does not work in Powershell:

$ws.Cells.Item($intRow,9).Formula = '=VLOOKUP("*"$([char]38)LEFT(G$intRow,5)$([char]38)"*",'\\compname\path\to\excel\[ramdata.xlsx]20151009'!A:B,2,FALSE)'

After I run the powershell script, the cell in which I am inserting the formula is blank.

Any ideas?

1 Answer 1

2

I was so close and needed to ask for help to find the answer!

$ws.Cells.Item($intRow,9).Formula = "=IF(ISBLANK(G$intRowMem),$([char]34)$([char]34),VLOOKUP($([char]34)*$([char]34)&LEFT(G$intRowMem,5)&$([char]34)*$([char]34),'\\compname\path\to\excel\[ramdata.xlsx]20151009'!A:B,2,FALSE))"

Is it ethical to answer your own question and mark your answer as the answer?

EDIT

Per @TheMadTechnician, this can also be solved as:

$ws.Cells.Item($intRow,9).Formula = "=IF(ISBLANK(G$intRowMem),`"`",VLOOKUP(`"*`"&LEFT(G$intRowMem,5)&`"*`",'\\compname\path\to\excel\[ramdata.xlsx]20151009'!A:B,2,FALSE))"
Sign up to request clarification or add additional context in comments.

4 Comments

Wow, you went through a lot of trouble to get those double quotes in there... in the future you can just escape them with a backtick (`) within your string to get them there, or double them up such as "The path ""C:\Temp"" doesn't actually need quotes around it" will appear as The path "c:\temp" doesn't actually need quotes around it. And it's just fine to accept your own answer if it actually answers the question.
I had used the backtick, but did not think it worked. What really happened is that I was trying to many things at once. I did try it and LONG and BEHOLD it worked just fine.
You can do it but you need to wait a bit: stackoverflow.com/help/accepted-answer
I know this is an old one by now, but THANK YOU! - Been pulling my hair for hours trying to figure this out! - i had tried the approach using ´"´" But didn't realize I had used the incorrect character to escape (´ instead of `)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.