Determine if cell exists in a specified range w/ Powershell Excel COM -


for example, i'm looking determine following logic:

if (b2 in a1:b20)  # if cell b2 within range a1:b20 {    return $true } 

is there function within excel can used this? read =countif() function not able working. again using excel com object within powershell.

thanks

since cell names coordinates, purely question of arithmetic comparison, no need involve excel itself:

function test-cellinrange {     param(         [validatepattern('^[a-z]+\d+$')]         [string]$cell,         [validatepattern('^[a-z]+\d+\:[a-z]+\d+$')]         [string]$range     )      # grab x , y coordinates range input, sort in ascending order (low high)     $p1,$p2 = $range -split ':'     $xpoints = ($p1 -replace '\d'),($p2 -replace '\d') |sort-object     $ypoints = ($p1 -replace '\d'),($p2 -replace '\d') |sort-object      # grab x , y coordinate cell     $cellx = $cell -replace '\d'     $celly = $cell -replace '\d'      # test whether cell coordinates within range     return ($cellx -ge $xpoints[0] -and $cellx -le $xpoints[1] -and $celly -ge $ypoints[0] -and $celly -le $ypoints[1]) } 

use like:

if(test-cellinrange -cell b2 -range a1:b20){     "b2 in a1:b20" } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -