How to get previous value if current cell value is empty?

I have a datatable like dis:

GroupName Location
XYZ London
ABC London
[empty] New York
GHQ New York

if the group name is empty then I have to consider the previous cell value…

how to tdo this?

Hey @cybzom

Follow the below steps…

  • Use a For Each Row activity to loop through the datatable
  • Inside the loop, Use a IF activity to check whether the value fo the current row is null or empty

if String.IsNullOrEmpty(row(“GroupName”).ToString)

if not null, assign the value to a string variable.

if null, use the value in the string variable, and assign it to the row which has the blank value

row(“GroupName”) = PreviousValueVariable

For each row in DT
     IF String.IsNullOrEmpty(row("GroupName").ToString)
          // Use the value in the variable
          // Assign the value to the string varibale to hold the current value

@Lahiru.Fernando it’s not working. I understood the logic sir but I don’t know why it’s not reflecting it the dt… I had a msg box its showing the proper yes no but not sure

here is a screenshot

Hi @cybzom

To get Previous value, use

FirstName = dt1.Rows(CInt(dt1.Rows.IndexOf(row).ToString)-1).Item(“First Name”).ToString


Is the scope of the previous value variable inside the for each row loop? Set it to outer sequence and try again…