Delete certain rows from a workbook

Thhere is a workbook where starting data starts with numbers and rest is starting with albhabets. I need to delete the data(rows) that starts with Numbers

Hi @ayushi_jain3 ,
You can try for each row
check condition by if
use remove data row

regards,
LNV

  1. Excel Application Scope:

    • Input: Path to your Excel workbook
    • Output: Workbook Application variable (let’s call it “excelApp”)
  2. Read Range:

    • Excel Application Scope: excelApp
    • SheetName: Name of the sheet you want to work with
    • Output: DataTable variable (let’s call it “data”)
  3. For Each Row (row in data):

    • Use a condition to identify rows you want to delete.
      For example: If row should be deleted,
      • Add Data Row: DataRow: row, DataTable: data, RowState: Deleted
  4. For Each Row (row in data.Rows):

    • Remove Data Row:
      • DataTable: data
      • DataRow: row

    (Loop in reverse order to avoid index issues)

  5. Write Range:

    • Excel Application Scope: excelApp
    • SheetName: Same sheet name
    • DataTable: data
  6. Close Workbook:

    • Excel Application Scope: excelApp
    • Save Workbook: True (if you want to save changes)

Hope it helps

@ayushi_jain3 - Try the Workflow I attached.

DeleteRowsWithNumericData.zip (17,8 KB)

It uses the Insert/Delete Rows activity:
image

The Target File looks like this:
image

And becomes this after the run:
image

Hope this helps! :slight_smile:

Actually, this is for Workbook and not excel. So the challenge is that I cannot Excel activities over here which needs Excel application Scope

You can try like this… @ayushi_jain3

1.Take for each row in data table and pass the
data table variable
2. Inside loop take if activity and pass condition
like this

If = Regex.Ismatch(CurrentRow(“ColumnName).ToString,”[0-9]+")

Then - you can remove the rows

Else - keep as it is blank

For the reference you can see the screenshot

It will remove the Row’s which having the digits

@ayushi_jain3

two ways

Directly on excel

  1. For each row in excel activity
  2. If condition with System.Text.RegularExpressions.Regex.IsMatch(currentrow.ByField("ColumnName").StringValue,"^\d.*")
  3. On the then side use delete rows activity with specific row and give position value as the index variable value from the for loop properties

From Datatable

  1. Read the data into datatable dt
  2. dt.AsEnumerable.Where(function(x) Not System.Text.RegularExpressions.Regex.IsMatch(x("ColumnName").Value,"^\d.*")).CopyToDatatable - this gives the required rows only
  3. use write datatable to write data to excel

cheers

Thanks @Anil_G , Tried the second solution and it worked

1 Like

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