How to do I use a filter to output a data table by column names, but column names is in a list of string and the list can change size?

How to do I use a filter to output a data table by column names, but column names is in a list of string and the list can change size?

I notice that I can use filter wizard to output the columns I want. But the problem is that I have my column names stored in a list of string that can come in different sizes. The filter wizard only allows me to input a certain amount of column names directly but does not take into account if the amount of column names changes throughout the code.

Example table:
image

For example my columns list is List(Of String)({“a”,“b”}) i.e. i want to only show columns “a” and “b”

Steps to filter datatable by column names thats in a list:::

  1. read datatable from excel e.g. to variable called dt
  2. assign New DataView(dt) to a dataview variable
  3. assign dataView.ToTable(false,new List(Of String)({"a","b"}).ToArray) to filteredTable variable
  4. now your filteredTable variable will be a table with only columns “a” and “b”
  5. you can use output data table + write line to print the new table
    image

Sequence:

2 Likes

Thank you Jack. This is great. It came with steps and visual aid.

1 Like

you’re welcome! good luck!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.