title: PowerShell Select Excel Cell
body: <p>I have an Excel sheet which is the product of multiple CSVs.  After all the pasting is completed and the file opens, I just want cell C5 to be selected.</p>
  <p>Previously in this script, my last step before closing all documents was <code>$Worksheet2.Range(&quot;C5&quot;).select()</code>.  It was working until I added a third CSV from which this Excel sheet ($Worksheet2) is pulling data.  Now I get <code>Unable to get the Select property of the Range class</code> and it leaves the last copy/paste area highlighted.  Help is appreciated.</p>
  <h1>Code Snippet</h1>
  <pre><code>#Copy the data from the export to Worklog Template file
  $Excel = New-Object -ComObject excel.application
  $Excel.visible = $false
  $WorkBook = $excel.Workbooks.Open($SAMTemp2)
  $WorkBook2 = $excel.Workbooks.open($Template)
  $Worksheet = $Workbook.WorkSheets.item(&quot;Export2&quot;)
  $Worksheet.activate()
  #Open the Planned SO Flags CSV
  $WorkBook3 = $excel.Workbooks.open($SAMTemp3)
  $Worksheet3 = $Workbook3.WorkSheets.item(&quot;Export3&quot;)
  $Worksheet3.activate()
  #SO Range Copy
  $rangeAc = $WorkSheet.Range(“B2:B26”)
  $rangeAc.Copy() | out-null
  #Select sheet 2
  $Worksheet2 = $Workbook2.Worksheets.item(“Worklog”)
  $worksheet2.activate()
  #SO Range Paste
  $rangeAp = $Worksheet2.Range(“K6:K30”)
  $rangeAp.PasteSpecial(-4163)
  
  #Target Range Copy
  $rangeC1c = $WorkSheet.Range(“F2:F26”)
  $rangeC1c.Copy() | out-null
  #Target Range Paste
  $rangeC1p = $Worksheet2.Range(“AC6:AC30”)
  $rangeC1p.PasteSpecial(-4163)
  #SODetails Range Copy
  $rangeC2c = $WorkSheet.Range(“D2:D26”)
  $rangeC2c.Copy() | out-null
  #SODetails Range Paste
  $rangeC2p = $Worksheet2.Range(“AB6:AB30”)
  $rangeC2p.PasteSpecial(-4163)
  #RowDetails Range Copy
  $rangeC2c = $WorkSheet.Range(“E2:E26”)
  $rangeC2c.Copy() | out-null
  #RowDetails Range Paste
  $rangeC2p = $Worksheet2.Range(“AD6:AD30”)
  $rangeC2p.PasteSpecial(-4163)
  
  #Trim Status down to &quot;O&quot; or &quot;C&quot; and paste...
  #Status Range Copy
  $rangeFc = $WorkSheet.Range(“C2:C26”)
  $rangeFc.Copy() | out-null
  #Status Range Paste
  $rangeFp = $Worksheet2.Range(“AA6:AA30”)
  $rangeFp.PasteSpecial(-4163)
  
  #Comments are just RowDetails again.
  #RowDetails Range Copy
  $rangeEc = $WorkSheet.Range(“E2:E26”)
  $rangeEc.Copy() | out-null
  #RowDetails Range Paste
  $rangeEp = $Worksheet2.Range(“P6:P30”)
  $rangeEp.PasteSpecial(-4163)
  
  $Worksheet2.Range(&quot;C6&quot;) = $TechName
  $Worksheet2.Range(&quot;C3:C4&quot;) = $VisitDate
  
  #Adds all planned SOs to the Planned SO section
  #Planned SO Range Copy
  $rangeGc = $WorkSheet3.Range(“B2:B16”)
  $rangeGc.Copy() | out-null
  #Planned SO Range Paste to the Planned SO section
  $rangeGp = $Worksheet2.Range(“F6:F20”)
  $rangeGp.PasteSpecial(-4163)
  
  #Hours Range Copy
  $rangeHc = $WorkSheet.Range(“I2:I16”)
  $rangeHc.Copy() | out-null
  #Hours Range Paste
  $rangeHp = $Worksheet2.Range(“L6:L20”)
  $rangeHp.PasteSpecial(-4163)
  
  #PlannedHours Range Copy
  $rangeHc = $WorkSheet3.Range(“I2:I16”)
  $rangeHc.Copy() | out-null
  #PlannedHours Range Paste
  $rangeHp = $Worksheet2.Range(“G6:G20”)
  $rangeHp.PasteSpecial(-4163)
  
  $Worksheet2.Item(&quot;C5&quot;).select()
  
  $workbook2.SaveAs($WorkLogSave)
  $workbook.close($true)
  $WorkBook3.close($true)
  </code></pre>