Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Excel conditional

$
0
0

Hello experts!

I am trying to read the number in a Excel cell (D2) If it is greater than 30 then I want it to replace the cell (F2) with "Good". Then I will need it to page down to cell (D3) and do the same  until it gets to an empty cell at the bottom of the D column. Here is my code thus far, the complete code is at the bottom. Not seeing a ton of code even similar to what i need on the web, so any help would be greatly appreciated. Thanks!

 

The Conditional so far:

 

$S1 = $Workbook.Worksheets.Item(1)
#$s1.range("D2","D100").cells=($scriptPath)


If ($s1.range("D2","D100").cells -Gt 30)
{
    $S2 = $Workbook.Worksheets.Item(1)
    $s2.range("F2","F100").cells=("Good")
    Exit
}
Esle

 

The Complete code:

 

$c = Get-Content C:\WORK\PAF_STATUS.xls | Measure-Object -line

$File = "C:\WORK\PAF_STATUS.xls"

# Setup Excel, open $File and set the the first worksheet
$Excel = New-Object -ComObject Excel.Application
$Excel.visible = $true
$Workbook = $Excel.workbooks.open($file)
$Worksheets = $Workbooks.worksheets
$Worksheet = $Workbook.Worksheets.Item(1)

$SearchString = "Some Value"

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
Get-Variable scriptPath


$S1 = $Workbook.Worksheets.Item(1)
#$s1.range("D2","D100").cells=($scriptPath)


If ($s1.range("D2","D100").cells -Gt 30)
{
    $S2 = $Workbook.Worksheets.Item(1)
    $s2.range("F2","F100").cells=("Good")
    Exit
}
Esle

$excel.DisplayAlerts = $false
$excel.ScreenUpdating = $false
$excel.Visible = $false
$excel.UserControl = $false
$excel.Interactive = $false

$Workbook.Save()
$workbook.Close()
$excel.Quit()


Viewing all articles
Browse latest Browse all 6937

Trending Articles