I have an excel vba code that finds a particular cell in a sheet. It uses the Find
method form the excel libraries. Here is the code
objRange.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows)
I need to do the same thing in powershell. But this method has a total of 9 arguments. How to ignore the other optional arguments in powershell. Something like this?
$range.Find("*", "", "", "", $xlByRows, $xlPrevious, "", "", "")
Here is the documentation of Range.Find
Method
By default, PowerShell parameters are optional. When a user does not submit arguments to a parameter, PowerShell uses its default value. If no default value exists, the parameter value is $null. This is not always desired.
To indicate optional arguments, Square brackets are commonly used, and can also be used to group parameters that must be specified together. To indicate required arguments, Angled brackets are commonly used, following the same grouping conventions as square brackets.
As the name suggests optional parameters are not compulsory parameters, they are optional. It helps to exclude arguments for some parameters. Or we can say in optional parameters, it is not necessary to pass all the parameters in the method. This concept is introduced in C# 4.0.
$null
doesn't work, but according to this answer you can use [Type]::Missing
:
$default = [Type]::Missing
$xl.Cells.Find("*", $default, $default, $default, $xlByRows, $xlPrevious,
$default, $default, $default)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With