How to apply filter based on row value digit count

Hi @Raja.G ,

Best and easiest solution would be to use Linq queries only as mentioned by @ppr and @Sudeen_Raj_Shetty

If you are new to this concept - I am giving you the step-by-step details and few minor points to be considered while using the regular expressions

Only 6 steps are involved for this

  1. Open the excel file where you need to apply the filter
  2. Read the data table and store to a variable (dtTable)
  3. Assign new data table variable (example dtvalid) with below regular expression as mentioned above. Make sure you have imported System.Text.RegularExpression in your project imports

dtvalid =
(From d In dtTable.AsEnumerable
Let v=d(1).ToString.Trim
Let chk =System.Text.RegularExpressions.Regex.IsMatch(v, “(^00[234]\d{4}$) | ([1]\d{4}$)”)
Where chk
Select r=d).CopyToDataTable

  1. Assign new data table variable (example dtinvalid) with below regular expression as mentioned above. Only difference to make is in where condition. Where chk=false

dtinvalid =
(From d In dtTable.AsEnumerable
Let v=d(1).ToString.Trim
Let chk =System.Text.RegularExpressions.Regex.IsMatch(v, “(^00[234]\d{4}$) | ([2]\d{4}$)”)
Where chk=false
Select r=d).CopyToDataTable

  1. Write data table to required sheets


  1. 234 ↩︎

  2. 234 ↩︎

1 Like