How to ignore string in between row

Hello,There is column called age…I need to convert it into Birth Year…i converted by using Date.now-year…but there is value between row which is in string How i need to write in excel file as invalid data in staus column
error in excel row

  1. Read Range (Read data from Excel into a DataTable)
  2. Add Data Column (Add a new DataColumn named “Status” of type String to the DataTable)
  3. For Each Row (For each row in DataTable)
    • Assign activity: ageValue = row(“Age”).ToString
    • Assign activity: birthYearValue = 0 (default value in case of invalid data)
    • If activity: Int32.TryParse(ageValue, birthYearValue)
      • Assign activity: birthYearValue = DateTime.Now.Year - birthYearValue
    • Else
      • Assign activity: row(“Status”) = “Invalid Data”
    • Assign activity: row(“Birth Year”) = birthYearValue.ToString
  4. Write Range (Write the updated DataTable back to Excel)
    Hope You Find it!
2 Likes

@sathya_auto

Excel Application Scope:
WorkbookPath: “Path_to_your_Excel_File.xlsx”
Read the range into a DataTable (let’s call it dtData)

For Each Row activity (row) in dtData:
Assign activity:
birthYear = Date.Now.Year - CInt(row(“Age”).ToString())

If-Else activity:
Condition: Integer.TryParse(row(“Age”).ToString(), age)
Then:
Assign activity:
row(“Birth Year”) = birthYear
row(“Status”) = “Processed”
Else:
Assign activity:
row(“Status”) = “Invalid Data”

Write Range activity:
Sheet: “Sheet1” (or the name of the sheet containing the data)
Range: “A1” (or the starting cell of your choice)
DataTable: dtData

@sathya_auto

System.Text.RegularExpressions.Regex.IsMatch(CurrentRow(“Age”).ToString,“[0-9]”)

Use this expression to check if the age column contains age or not. If false then write invalid data in status column

Got it thankyou rigandu and tazunnisa

1 Like

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