Read Range - Brings new empty columns (Column1,Column2,Column3....)

My suggestion is with the assumption that any phantom data gets added to a column that starts with “Column”. The order doesn’t matter at all.

Basically, I have created an array of the columns that start with “Column”, then run that in the loop to remove them.

dt.Columns.Cast(Of DataColumn).Where(Function(c) c.ColumnName.StartsWith("Column") ).ToArray
this line of code sets an array with only the columns that starts with “Column”. Alternatively, you can run an IF inside that checks the StartsWith() instead, however, that is less efficient.

So, it ends up looking like this:


where the For each is of TypeArgument String, although, you can change it to DataColumn and remove the .Select() part out of it, if you wanted. Then, use col.ColumnName

Here is the example without the IF which I think is better:


where the For each is of TypeArgument DataColumn
@Mario9016

1 Like