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

How to add Data Vlidation Drop Down List in Excel with Powershell

$
0
0

I am working on a powershell script to create an Excel spread sheet but I am stuck trying to add some Data validation Drop Down Lists.  The below code creates and populates the spread sheet but I need to make cells F2:F5 drop down options for cells B2 on down and cells G2:G5 drop down options for cells C2 on down.  I have been doing a lot of searching but can't seam to find a solution to this problem.  Any help would be great!

 

$OutObj | Add-Member -type NoteProperty -Name ItemNum -Value ""
$OutObj | Add-Member -type NoteProperty -Name Color -Value ""
$OutObj | Add-Member -type NoteProperty -Name Size -Value ""
$OutObj | Add-Member -type NoteProperty -Name Owner -Value ""

$Excel = "$env:temp\TestWorkbook.csv"
$OutObj | Export-CSV $Excel -NoTypeInformation
$ExcelObject = New-Object -ComObject Excel.Application
$ExcelObject.Workbooks.Open($Excel)
$ExcelObject.Visible = $true

$ExcelObject.Cells.Item(1,6) = 'Do not modify the below!'
$ExcelObject.Cells.Item(2,6) = 'Red'
$ExcelObject.Cells.Item(3,6) = 'Blue'
$ExcelObject.Cells.Item(4,6) = 'Green'
$ExcelObject.Cells.Item(5,6) = 'Yellow'

$ExcelObject.Cells.Item(2,7) = 'Small'
$ExcelObject.Cells.Item(3,7) = 'Medium'
$ExcelObject.Cells.Item(4,7) = 'Large'
$ExcelObject.Cells.Item(5,7) = 'XL'


Viewing all articles
Browse latest Browse all 6937

Trending Articles