How to add two columns in a excel in a specific format

I have two column in a excel sheet. I need to add the two columns in a specific format.The output should be Column B Value - Currentdate - ColumnA value.I have attached sample file for reference.
Book1.xlsx (8.9 KB)

Hey @sathish_moorthy I got you!, I’m solving this can you tell me you will have a empty 3rd column name “Output” or We have to add a new column into your input table?

@sathish_moorthy Here is the output!

Use Invoke code:

Dim str_Output As String
str_Output = “”
io_dt_Input.AsEnumerable().ToList.ForEach(
Sub(x)
x(“Output”)=x(“Payer”).ToString+Now.ToString(“-dd.MM.yyyy-”)+x(“Company Code”).ToString
End Sub)

Attaching a .zip for your reference, It consist of .xaml and Input-Output File sheet!
AddTwoColumnValues.zip (10.3 KB)

If your issue will resolve, kindly mark this post as solution. So, that other will get right solution!

Happy Automation!

Regards,
Ajay Mishra

1 Like

Hi @sathish_moorthy ,
you can use Invoke code activity ,

image

Dim currentDate As String = DateTime.Now.ToString(“dd.MM.yyyy”)

If Not dtInput.Columns.Contains(“Output”) Then
dtInput.Columns.Add(“Output”, GetType(String))
End If

For Each row As DataRow In dtInput.Rows
Dim payer As String = row(“Payer”).ToString()
Dim companyCode As String = row(“Company Code”).ToString()
row(“Output”) = $“{payer}-{currentDate}-{companyCode}”
Next

  • We first check if the “Output” column exists in dtInput using dtInput.Columns.Contains("Output").
  • If it doesn’t contain the column, we add it using dtInput.Columns.Add("Output", GetType(String)).
  • Then, we iterate through each row in dtInput, calculate the “Output” value based on the specified format, and update the corresponding row in the “Output” column.

Thanks ,

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