Hi
I have the following code that reads Excel file. It has 2 work sheets. One called Input the other called Targeted. Please see following.
I want to match in the input worksheet thos columns “B” and “C” to To worksheet Targeted Columns “C” and “E”.
Once there is a match then I would Like to replace Value of Column “o” in the Input worksheet to Value of column “H” in the worksheet Targeted.
I have following code that worls and reads correct columns and values from INPUT worksheet.
$File = "c:\Excel\converted2_txt_csv.xlsx"
# Setup Excel, open $File and set the the first worksheet
$Excel = New-Object -ComObject Excel.Application
$Excel.visible = $False
$Workbook = $Excel.workbooks.open($file)
$Worksheets = $Workbooks.worksheet
$Worksheet1 = $Workbook.Worksheets.Item(1)
$Worksheet2 = $Workbook.Worksheets.Item(2)
#Echo $Worksheet
#Echo $Worksheet2
$intRowMax = ($worksheet.UsedRange.Rows).count
$intColMax = ($worksheet.UsedRange.Columns).count
#select total rows
$rowMax = ($Worksheet1.UsedRange.Rows).Count
#create new object with Name, Address, Email properties.
$myData = New-Object -TypeName psobject
$myData | Add-Member -MemberType NoteProperty -Name AccountNumber -Value $null
$myData | Add-Member -MemberType NoteProperty -Name AccountName -Value $null
#$myData | Add-Member -MemberType NoteProperty -Name Email -Value $null
# #Write-Host "Processing: " $intRowMax " rows" "and columns " $intColMax
for ($i = 1; $i -le $rowMax; $i++)
{
$objTemp = $myData | Select-Object *
Echo $objTemp
#read data from each cell
$objTemp.AccountNumber = $Worksheet1.Cells.Item($i,2).Text
$objTemp.AccountName = $Worksheet1.Cells.Item($i,3).Text
# Write-Host 'AccountNumber' $objTemp.AccountNumber 'AccountName-' $objTemp.AccountName
# Echo $objTemp.AccountNumber
# Echo $objTemp.AccountName
# If ($Worksheet2.Item(2).Range("A:Z").Find($objTemp.AccountNumber))
Echo $objTemp.AccountNumber
}