title: Why merge cells doesn't work with powershell
body: <p>I have a powershell script to merge some cells in excel but doesn't work.
  Can anyone help to check why? somehow the picture i loaded here are not accesible</p>
  
  <p>seems it simply removed some data but didn't do the merge work.</p>
  
  <pre><code>$ExportFile = "I:\SCRIPT\IPCNewScript\Result.csv"
  
  $xlShiftDown = -4121
  $objExcel=New-Object -ComObject Excel.Application
  #$objExcel.Visible=$true
  $objExcel.DisplayAlerts = FALSE
  
  $WorkBook=$objExcel.Workbooks.Open($ExportFile)
  
  $worksheet = $workbook.sheets.item("Result")
  
  #Get row &amp; column count
  $objRange = $worksheet.UsedRange
  $RowCount = $objRange.Rows.Count
  $ColumnCount = $objRange.Columns.Count
  
  for ( $i=3 ; $i -le 4; $i ++ ){
       $inc = 1
       $NexRow = $i + $inc
      for ( $j=1 ; $j -le 3; $j ++ ){
  
          $worksheet.Cells.Item($i,$j).Text
          $worksheet.Cells.Item($NexRow,$j).Text
          $MergeCells = $worksheet.Range($worksheet.Cells.Item($i,$j), $worksheet.Cells.Item($NexRow,$j))
          $MergeCells.Select() 
          $MergeCells.MergeCells = $true
          $MergeCells.Font.ColorIndex = 11 
  
          #$objRange.EntireColumn.AutoFit() | Out-Null
      }
  }
  $WorkBook.Save()
  $objExcel.Quit()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/f2EmF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f2EmF.jpg" alt="enter image description here"></a></p>