<?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 VBA Code - Filter using Array in Product Forum</title>
    <link>https://community.blueprism.com/t5/Product-Forum/VBA-Code-Filter-using-Array/m-p/48595#M4106</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;i need to filter data in Excel spreadsheet. It can be dynamic number of values (or). In the vba code it should look like below:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Worksheets(&lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"Sheet1"&lt;/SPAN&gt;&lt;SPAN&gt;).ListObjects(&lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"Table1"&lt;/SPAN&gt;&lt;SPAN&gt;).Range.AutoFilter _ Field:=&lt;/SPAN&gt;&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;, _ Criteria1:=Array(&lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"1"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"3"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"Seattle"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"Redmond"&lt;/SPAN&gt;&lt;SPAN&gt;), _ &lt;/SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;Operator&lt;/SPAN&gt;&lt;SPAN&gt;:=xlFilterValues&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;but in the Blue Prism Code Stage it is not accepted&lt;BR /&gt;&lt;BR /&gt;ws.usedRange.AutoFilter(field:=ColumnNumber, Criteria1:=Array(Criteria1), Operator:=7)&lt;BR /&gt;&lt;BR /&gt;How can I filter using array in the Blue Prism?&lt;BR /&gt;&lt;BR /&gt;Page: FilterData Array&lt;BR /&gt;Stage: FilterData Array&lt;BR /&gt;Type: Error&lt;BR /&gt;Action: Validate&lt;BR /&gt;Description: Compiler error at line 8: 'Array' is a class type and cannot be used as an expression.&lt;BR /&gt;Repairable: No&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;Mateusz&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Mateusz Blazej&lt;BR /&gt;RPA Developer&lt;BR /&gt;VELUX&lt;BR /&gt;Europe/Warsaw&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
    <pubDate>Mon, 09 May 2022 12:51:00 GMT</pubDate>
    <dc:creator>matbla91</dc:creator>
    <dc:date>2022-05-09T12:51:00Z</dc:date>
    <item>
      <title>VBA Code - Filter using Array</title>
      <link>https://community.blueprism.com/t5/Product-Forum/VBA-Code-Filter-using-Array/m-p/48595#M4106</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;i need to filter data in Excel spreadsheet. It can be dynamic number of values (or). In the vba code it should look like below:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Worksheets(&lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"Sheet1"&lt;/SPAN&gt;&lt;SPAN&gt;).ListObjects(&lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"Table1"&lt;/SPAN&gt;&lt;SPAN&gt;).Range.AutoFilter _ Field:=&lt;/SPAN&gt;&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;, _ Criteria1:=Array(&lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"1"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"3"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"Seattle"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"Redmond"&lt;/SPAN&gt;&lt;SPAN&gt;), _ &lt;/SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;Operator&lt;/SPAN&gt;&lt;SPAN&gt;:=xlFilterValues&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;but in the Blue Prism Code Stage it is not accepted&lt;BR /&gt;&lt;BR /&gt;ws.usedRange.AutoFilter(field:=ColumnNumber, Criteria1:=Array(Criteria1), Operator:=7)&lt;BR /&gt;&lt;BR /&gt;How can I filter using array in the Blue Prism?&lt;BR /&gt;&lt;BR /&gt;Page: FilterData Array&lt;BR /&gt;Stage: FilterData Array&lt;BR /&gt;Type: Error&lt;BR /&gt;Action: Validate&lt;BR /&gt;Description: Compiler error at line 8: 'Array' is a class type and cannot be used as an expression.&lt;BR /&gt;Repairable: No&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;Mateusz&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Mateusz Blazej&lt;BR /&gt;RPA Developer&lt;BR /&gt;VELUX&lt;BR /&gt;Europe/Warsaw&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Mon, 09 May 2022 12:51:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/VBA-Code-Filter-using-Array/m-p/48595#M4106</guid>
      <dc:creator>matbla91</dc:creator>
      <dc:date>2022-05-09T12:51:00Z</dc:date>
    </item>
    <item>
      <title>RE: VBA Code - Filter using Array</title>
      <link>https://community.blueprism.com/t5/Product-Forum/VBA-Code-Filter-using-Array/m-p/48596#M4107</link>
      <description>Hi Mateusz,&lt;BR /&gt;&lt;BR /&gt;You can create a new action called 'Filter Values' by extending the &lt;SPAN&gt;'&lt;/SPAN&gt;&lt;STRONG&gt;MS Excel&lt;/STRONG&gt;&lt;SPAN&gt;' VBO object which consists of other actions. Add the following input parameters to this action:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Handle (Number) : The instance of the excel sessions held in the dictionary to establish the current excel connection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Workbook Name (Text) : The workbook name returned while using either 'Open Workbook' or 'Create Workbook' actions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Worksheet Name (Text) : The worksheet name where the operation needs to be performed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Table Name (Text) : The name of the table where the action needs to be performed.&lt;BR /&gt;&lt;BR /&gt;- Field Index (Text) : The index of the column where filter needs to be applied starting from the position 1 to N.&lt;BR /&gt;&lt;BR /&gt;- Array Values (Collection) : The collection with a single column named '&lt;STRONG&gt;Field Values&lt;/STRONG&gt;' comprising of all the filter values for the selected field index column&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16391.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16541i24963C834C3ED298/image-size/large?v=v2&amp;amp;px=999" role="button" title="16391.png" alt="16391.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Prerequisite:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Add the following Namespace Import and External Reference in the Page Descriptions stage of the Initialize page:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16392.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16547i32E6D90A6C537DBC/image-size/large?v=v2&amp;amp;px=999" role="button" title="16392.png" alt="16392.png" /&gt;&lt;/span&gt;&lt;BR /&gt;Also, ensure that the following DLL is installed inside your Blue Prism installation folder. I have provided the same in the attached zip file:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16393.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16546iB22DBB70439A01BC/image-size/large?v=v2&amp;amp;px=999" role="button" title="16393.png" alt="16393.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Solution Workflow:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16394.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16549i8E9DF89442A07A17/image-size/large?v=v2&amp;amp;px=999" role="button" title="16394.png" alt="16394.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16395.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16548i2A1DF26844A750B6/image-size/large?v=v2&amp;amp;px=999" role="button" title="16395.png" alt="16395.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;Now add a code stage called 'Filter Values' with the following parameters and code:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16396.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16550iC0C8D29AC5FDD4E9/image-size/large?v=v2&amp;amp;px=999" role="button" title="16396.png" alt="16396.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16397.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16553i4CB60AB39B82C1E5/image-size/large?v=v2&amp;amp;px=999" role="button" title="16397.png" alt="16397.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;CODE&gt;Dim wb, ws As Object&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;Dim excel, sheet As Object&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;Dim StrList As New List(Of String)&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;wb = GetWorkbook(Handle, Workbook_Name)&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;ws = GetWorksheet(Handle, Workbook_Name, Worksheet_Name)&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;wb.Activate()&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;ws.Activate()&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;excel = ws.Application&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;sheet = excel.ActiveSheet&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;For Each row As DataRow In Array_Values.Rows&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;If row("Field Values") IsNot Nothing Then&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;StrList.Add(row("Field Values").ToString)&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;End If&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Next&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;sheet.ListObjects(Table_Name).Range.AutoFilter(Field:=Field_Index, Criteria1:=StrList.ToArray(),Operator:=Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlFilterValues)&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Test Scenario:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;I have the following excel file where I will be filtering the table based on few of the product names:&lt;STRONG&gt;&lt;/STRONG&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16398.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16554iBAD9657158310583/image-size/large?v=v2&amp;amp;px=999" role="button" title="16398.png" alt="16398.png" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;I will be passing the field index as '2' since I want to apply filter on second column along with the following array values collection:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16399.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16552i253B6FD4FE11D2D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="16399.png" alt="16399.png" /&gt;&lt;/span&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16400.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16551i60451D8B79C36D54/image-size/large?v=v2&amp;amp;px=999" role="button" title="16400.png" alt="16400.png" /&gt;&lt;/span&gt;&lt;BR /&gt;Upon running the workflow, I get the following output:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16401.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16556iE41A338E2F10E666/image-size/large?v=v2&amp;amp;px=999" role="button" title="16401.png" alt="16401.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="16402.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/16558i6138FDF0C0D34394/image-size/large?v=v2&amp;amp;px=999" role="button" title="16402.png" alt="16402.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;----------------------------------&lt;BR /&gt;Hope it helps you out and if my solution resolves your query, then please mark it as the 'Best Answer' so that the others members in the community having similar problem statement can track the answer easily in future&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Devneet Mohanty&lt;BR /&gt;Intelligent Process Automation Consultant | Sr. Consultant - Automation Developer,&lt;BR /&gt;Wonderbotz India Pvt. Ltd.&lt;BR /&gt;Blue Prism Community MVP | Blue Prism 7x Certified Professional&lt;BR /&gt;Website: &lt;A href="https://devneet.github.io/" target="test_blank"&gt;https://devneet.github.io/&lt;/A&gt;&lt;BR /&gt;Email: devneetmohanty07@gmail.com&lt;BR /&gt;&lt;BR /&gt;----------------------------------&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Mon, 09 May 2022 14:20:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/VBA-Code-Filter-using-Array/m-p/48596#M4107</guid>
      <dc:creator>devneetmohanty07</dc:creator>
      <dc:date>2022-05-09T14:20:00Z</dc:date>
    </item>
  </channel>
</rss>

