Skip to main content
Ground Control | Tier 1
January 18, 2023
Question

How to delete specific rows in a Datatable ?

  • January 18, 2023
  • 13 replies
  • 5238 views

For example : Here I need to delete rows contain “bbb” and “ccc”
 

The output should contain only rows with “aaa”

 

13 replies

Flight Specialist | Tier 4
April 13, 2023

@Sumit.K7 ok I was able to use your method BUT I had to first use the Assign command to create the columns needed in the target table:

  1. Add data to table 1 using Excel Advanced
  2. Add data to table 1 using Assign command (assign table 1 to table 2)
  3. Use the Clear Content command on table 2
  4. Loop table 1 and add rows to table 2 when certain criteria is met

This successfully adds rows to table 2 from table 1 with the same columns.

Cadet | Tier 2
December 6, 2023

Esto es lo que me funciono, saludos a todos

 

 

Cadet | Tier 2
March 13, 2024

I have a successful logic to delete specific rows in a data table.

Now, we are aware that the counter starts from 0. Now you can follow the steps to achieve the outcome.

  1. Loop through the data table, with String if condition (Table[0] != aaa) and store the row numbers into a list say “tempList” 
  2. now set a counter value to 0
  3. Now loop through the Temp list which is created, store the current list iten in current row, in that loop add the following:
    • Current = Current row - Counter 
    • Delete Current row
    • counter + 1

That's it.!!!

 

Explanation is below for second loop:

In the above example you know that the row numbers that has to be deleted are: 1, 4 & 5

TempList = 1, 4, 5

Once we start the loop, first value of current row = 1 and counter = 0. so when you subtract counter with current row you get current row value as 1. so you use delete row at 1. (see fig “original table”)

on next iteration, current row = 4 and counter = 1, Hence, on subtraction current row = 4-1=3, which is deleting row at 3 (see fig “when row number 1 is already deleted from the original)

and similarly, 5 - 2 = 3 and so on..

AA code sample:

 

I hope this helps!😄