title: Append from the last row on-wards Excel & Powershell
body: <p>I am currently working on a script that would keep track of the size of databases across different network servers. I am outputting the results to an excel, this will run every day, hence, I need to know how I can get the last row which contains data and append from there on-wards. </p>
  
  <pre><code>#Creates heading on an excel file if the file did not exist previously
  Function CreateExcelWithHeadings($intRow, $Sheet)
  {
  $intRow++
  #Create column headers
  $Sheet.Cells.Item($intRow,1)= "Date"
  $Sheet.Cells.Item($intRow,1).Font.Size = 12
  $Sheet.Cells.Item($intRow,1).Font.Bold = $True
  
  $Sheet.Cells.Item($intRow,2) = "Server"
  $Sheet.Cells.Item($intRow,2).Font.Size = 12
  $Sheet.Cells.Item($intRow,2).Font.Bold = $True
  
  #$intRow++
  $Sheet.Cells.Item($intRow,3) = "Database"
  $Sheet.Cells.Item($intRow,3).Font.Bold = $True
  $Sheet.Cells.Item($intRow,4) = "Data Name"
  $Sheet.Cells.Item($intRow,4).Font.Bold = $True
  $Sheet.Cells.Item($intRow,5) = "Data File"
  $Sheet.Cells.Item($intRow,5).Font.Bold = $True
  $sheet.Cells.Item($intRow,6) = "Data Size (MB)"
  $Sheet.Cells.Item($intRow,6).Font.Bold = $True
  $Sheet.Cells.Item($intRow,7) = "Data Used Space (MB)"
  $Sheet.Cells.Item($intRow,7).Font.Bold = $True
  $Sheet.Cells.Item($intRow,8) = "Log Name"
  $Sheet.Cells.Item($intRow,8).Font.Bold = $True
  $Sheet.Cells.Item($intRow,9) = "Log Size (MB)"
  $Sheet.Cells.Item($intRow,9).Font.Bold = $True
  $Sheet.Cells.Item($intRow,10) = "Log Used Space (MB)"
  $Sheet.Cells.Item($intRow,10).Font.Bold = $True
  $Sheet.Cells.Item($intRow,11) = "Log File"
  $Sheet.Cells.Item($intRow,11).Font.Bold = $True  
  }
  # initalize variables 
  $serverList = "C:\Database Monitor\sqlservers.txt"
  $filepath ='C:\Database Monitor\Log Files\' 
  $filename = 'database_logging.xlsx' 
  #Create a new Excel object using COM 
  $Excel = New-Object -ComObject Excel.Application
  # check if file path exists, if its doesn't create one with the proper headings
  If (-not (Test-Path -path $filepath))
  {
  New-Item -ItemType directory -Path $filepath
  $Excel.visible = $True
  $Excel = $Excel.Workbooks.Add()
  $Sheet = $Excel.Worksheets.Item(1)
  CreateExcelWithheadings 0 $Sheet
  $Sheet.SaveAs($filepath+$filename)
  #WritetoExcel($serverList, 0)
  
  }
  Else
  {
  $Excel.visible = $True
  $Excel = $Excel.Workbooks.Open($filepath)
  $Sheet = $Excel.Worksheets.Item(1)
  $ExcelWorkSheet.activate()
  #$lastRow = 
   }
  </code></pre>