Hi, I have an Excel table that has multiple rows and columns.
I get a unique ID and I need to delete the row that has that ID (row name is “ID”).
How could I do that efficiently. Do I really need to go through all rows or is there a direct command?
->e.g. ID=123987
You will have to open excel application scope
read the range “” in the correct sheet and create a datatable
do a for each row in the data table
run a if condition to check if any of the row contains ID= 123987
if condition is true remove data row else do nothing
i am just not able to write the condition in which we can run the if statement to check the id
I kind of agree that you really don’t want to loop through each row just to find the correct row. So the method to use so you don’t need to loop through each row is to filter your data down to an array of rows. You can do this using LINQ, and I apologize if this is too technically - using .Select() or preferrably .Where(Function(r) )
Another thing to know is that when you filter this data, you will get potentially multiple rows that match, so you need to run the new array through a For each to delete them. And, since they are an array of rows, the original data set is referenced by this array so they are deleted from it.
here is pseudocode that represents this idea:
Assign activity: arrRows = dt1.AsEnumerable.Where(Function(r) r("ID").ToString.Trim = "123987" ).ToArray
For each row in arrRows 'TypeArgument: DataRow'
Delete Row activity: DataRow => row, DataTable => dt1