<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Retrieving the last row of an Excel spreadsheet to delete when the row is dynamic in Product Forum</title>
    <link>https://community.blueprism.com/t5/Product-Forum/Retrieving-the-last-row-of-an-Excel-spreadsheet-to-delete-when/m-p/54301#M8846</link>
    <description>I am trying to retrieve the last row of an Excel spreadsheet (which the last row is dynamic) in order to delete it then save the file.&amp;nbsp; I used an Excel VBO Business Object and was able to count the number of rows and output that number into a data item (to be used to identify the last row of the spreadsheet).&amp;nbsp; However when I run the process and it gets to the step where I have an action that uses the Excel VBO Business Object with the Action "Select", and reference the previously created data item as the Cell Reference value, its erroring (Exception: Failed to select row: Exception from HRESULT:0x800A03EC).&amp;nbsp; I entered the Value of the Cell Reference as "[Number of Rows]:[Number of Rows]".&amp;nbsp; I also tried using "[Number of Rows]".&amp;nbsp; Got the same error. Since the Cell Reference has to be of type Text, I changed the data item's type to Text but still getting the same error.&amp;nbsp; If I input numbers as the Cell Reference instead (Ex. "1:5"), it works.&amp;nbsp; Is there a simple fix for this?&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Angela Barnes&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
    <pubDate>Wed, 11 Aug 2021 13:15:00 GMT</pubDate>
    <dc:creator>AngelaBarnes</dc:creator>
    <dc:date>2021-08-11T13:15:00Z</dc:date>
    <item>
      <title>Retrieving the last row of an Excel spreadsheet to delete when the row is dynamic</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Retrieving-the-last-row-of-an-Excel-spreadsheet-to-delete-when/m-p/54301#M8846</link>
      <description>I am trying to retrieve the last row of an Excel spreadsheet (which the last row is dynamic) in order to delete it then save the file.&amp;nbsp; I used an Excel VBO Business Object and was able to count the number of rows and output that number into a data item (to be used to identify the last row of the spreadsheet).&amp;nbsp; However when I run the process and it gets to the step where I have an action that uses the Excel VBO Business Object with the Action "Select", and reference the previously created data item as the Cell Reference value, its erroring (Exception: Failed to select row: Exception from HRESULT:0x800A03EC).&amp;nbsp; I entered the Value of the Cell Reference as "[Number of Rows]:[Number of Rows]".&amp;nbsp; I also tried using "[Number of Rows]".&amp;nbsp; Got the same error. Since the Cell Reference has to be of type Text, I changed the data item's type to Text but still getting the same error.&amp;nbsp; If I input numbers as the Cell Reference instead (Ex. "1:5"), it works.&amp;nbsp; Is there a simple fix for this?&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Angela Barnes&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Wed, 11 Aug 2021 13:15:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Retrieving-the-last-row-of-an-Excel-spreadsheet-to-delete-when/m-p/54301#M8846</guid>
      <dc:creator>AngelaBarnes</dc:creator>
      <dc:date>2021-08-11T13:15:00Z</dc:date>
    </item>
    <item>
      <title>RE: Retrieving the last row of an Excel spreadsheet to delete when the row is dynamic</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Retrieving-the-last-row-of-an-Excel-spreadsheet-to-delete-when/m-p/54302#M8847</link>
      <description>Hi Angela&lt;BR /&gt;&lt;BR /&gt;The number of rows is returning the count but no column number or letter you can use the count to select the cell as long as you know the column of the cell you want to delete the value from. For example if the column you want to select is A and the row count is 27 then in the select action enter "A"&amp;amp;[Number of Rows] and this selects the cell A27. Similarly if you need to select a range of rows and you know the start and end columns then enter "A"&amp;amp;[Number of Rows]&amp;amp;":G"&amp;amp;[Number of Rows] which would be A27:G27.&lt;BR /&gt;&lt;BR /&gt;If you would rather you got the cell reference then you can use the action Find Next empty cell and this will get the last empty cell and you would need to do an calculation to amend the cell reference to reduce the rows by 1. If you have a lot of rows though this action can be very slow.&lt;BR /&gt;&lt;BR /&gt;Alternatively if you are ok with coding in VB then there are a couple of options you can create a new action to get the last row with value, example code is below:&lt;BR /&gt;&lt;BR /&gt;Dim wb, ws As Object&lt;BR /&gt;Dim excel, sheet, range As Object&lt;BR /&gt;&lt;BR /&gt;Try&lt;BR /&gt;&lt;BR /&gt;wb = GetWorkbook(Handle, Workbook)&lt;BR /&gt;ws = GetWorksheet(Handle, Workbook, Worksheet)&lt;BR /&gt;&lt;BR /&gt;wb.Activate()&lt;BR /&gt;ws.Activate()&lt;BR /&gt;excel = ws.Application&lt;BR /&gt;sheet = excel.ActiveSheet&lt;BR /&gt;range = sheet.Range(StartCell)&lt;BR /&gt;range.Select()&lt;BR /&gt;range.End(direction).Activate()&lt;BR /&gt;&lt;BR /&gt;Success = True&lt;BR /&gt;cellref = excel.ActiveCell.Address(false, false)&lt;BR /&gt;&lt;BR /&gt;Catch e As Exception&lt;BR /&gt;Success = False&lt;BR /&gt;Message = e.Message&lt;BR /&gt;Finally&lt;BR /&gt;wb = Nothing&lt;BR /&gt;ws = Nothing&lt;BR /&gt;excel = Nothing&lt;BR /&gt;sheet = Nothing&lt;BR /&gt;range = Nothing&lt;BR /&gt;End Try&lt;BR /&gt;&lt;BR /&gt;Inputs will be Handle, Workbook, Worksheet, direction and starting cell. Direction you will need to set as DOWN, UP, LEFT or RIGHT and you will need to use a calculation stage prior to the code stage and set the enumerator depending on the which input direction was given. &lt;BR /&gt;&lt;BR /&gt;A simpler code stage would be to delete the entire row you want to remove. The code is below:&lt;BR /&gt;Dim wb, ws As Object&lt;BR /&gt;Dim strDir as String = direction.Trim().Substring(0,1).ToUpper()&lt;BR /&gt;Dim dirn as Integer = 0&lt;BR /&gt;Dim excel, sheet, range As Object&lt;BR /&gt;&lt;BR /&gt;wb = GetWorkbook(Handle, Workbook)&lt;BR /&gt;ws = GetWorksheet(Handle, Workbook, Worksheet)&lt;BR /&gt;&lt;BR /&gt;wb.Activate()&lt;BR /&gt;ws.Activate()&lt;BR /&gt;excel = ws.Application&lt;BR /&gt;sheet = excel.ActiveSheet&lt;BR /&gt;range = sheet.Range(Reference)&lt;BR /&gt;range.Select()&lt;BR /&gt;&lt;BR /&gt;Select Case strDir&lt;BR /&gt;Case "U"&lt;BR /&gt;dirn = -4162 ' Excel.XlDirection.xlToUp&lt;BR /&gt;Case "L"&lt;BR /&gt;dirn = -4159 ' Excel.XlDirection.xlToLeft&lt;BR /&gt;Case "R"&lt;BR /&gt;dirn = -4161 ' Excel.XlDirection.xlToRight&lt;BR /&gt;Case Else&lt;BR /&gt;Throw New ArgumentException("Invalid Direction: " &amp;amp; strDir)&lt;BR /&gt;End Select&lt;BR /&gt;&lt;BR /&gt;range.Delete(Shift:=dirn)&lt;BR /&gt;&lt;BR /&gt;'If direction = "UP"&lt;BR /&gt;'range.Delete(Shift:=-4162)&lt;BR /&gt;'else range.Delete(Shift:=-4159)&lt;BR /&gt;'end if&lt;BR /&gt;&lt;BR /&gt;The inputs for this code stage and the action are the Handle, Workbook, Worksheet and Reference. The reference is the row range which after using the action count rows you can use the data item to delete this row and you should just enter this as [Number of Rows]&amp;amp;":"&amp;amp;[Number of Rows]&lt;BR /&gt;&lt;BR /&gt;Hopefully this makes sense.&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Michael ONeil&lt;BR /&gt;Technical Lead developer&lt;BR /&gt;Everis Consultancy&lt;BR /&gt;Europe/London&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Wed, 11 Aug 2021 13:46:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Retrieving-the-last-row-of-an-Excel-spreadsheet-to-delete-when/m-p/54302#M8847</guid>
      <dc:creator>michaeloneil</dc:creator>
      <dc:date>2021-08-11T13:46:00Z</dc:date>
    </item>
    <item>
      <title>RE: Retrieving the last row of an Excel spreadsheet to delete when the row is dynamic</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Retrieving-the-last-row-of-an-Excel-spreadsheet-to-delete-when/m-p/54303#M8848</link>
      <description>Hi &lt;a href="https://community.blueprism.com/t5/user/viewprofilepage/user-id/32295"&gt;@AngelaBarnes&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;The simplest solution would be to use the below expression in the select action of MS Excel VBO: &lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;[Number of Rows] &amp;amp; ":" &amp;amp; [Number of Rows]&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;Please use the correct syntax and you will be able to delete the last row. Hope it helps !!​&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Ritansh Jatwani Senior Consultant&lt;BR /&gt;Consultant&lt;BR /&gt;EY&lt;BR /&gt;Gurgaon&lt;BR /&gt;*If you find this post helpful mark it as best answer&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Wed, 11 Aug 2021 19:46:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Retrieving-the-last-row-of-an-Excel-spreadsheet-to-delete-when/m-p/54303#M8848</guid>
      <dc:creator>ritansh.jatwani</dc:creator>
      <dc:date>2021-08-11T19:46:00Z</dc:date>
    </item>
  </channel>
</rss>

