Powershell; writing formuals into Excel

Neil Armani 1 Reputation point
2021-02-08T07:09:58.4+00:00

Looking for help;
In using the powershell line to insert a formula, for example:

$formula = “=Unique(B1#)”
$ws.Cells.Item(1,4).Formula = $formula

My formulas all insert with (using the above as the example):
=@unique (B1#)

How can I insert a formula without the ‘@’ being added?
(O365)

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,576 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Neil Armani 1 Reputation point
    2021-02-08T07:15:46.853+00:00

    Before I touch my Reports spreadsheet, I'm trying to solve this problem on my test sheet with a 'Test' tab in it ... if it helps, my Powershell for this test is;

    $xl=New-Object -ComObject Excel.Application
    $wb=$xl.WorkBooks.Open('C:\Temp\Excel_Report\Test_Formula.xlsx')
    $page1 = 'Test'
    $ws = $wb.worksheets | where-object {$_.Name -eq $page1}
    $xl.Visible=$false
    $formula = "=Unique(B1#)"
    $ws.Cells.Item(1,4).Formula = $formula

    $wb.Save()
    $xl.Quit()

    0 comments No comments

  2. Ian Xue 38,386 Reputation points Microsoft Vendor
    2021-02-09T08:01:32.24+00:00

    Hi,

    The @ is an implicit intersection operator.
    https://support.microsoft.com/en-us/office/implicit-intersection-operator-ce3be07b-0101-4450-a24e-c1c999be2b34?ui=en-US&rs=en-US&ad=US

    As the issue is more related to office, please start a new thread with the "office-itpro" tag if you don't want the operator to be added automatically.

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.