How to Write Cell that is in a data loop with If

Hi All,

I use a For Each Row to build a DataTable
In the For Each Row Sequence i have a If activities
If there is a certain condition i would like to write cell with a “text”
Else i would like to write cell with another “text”

In the If:
i use write cell and set the range as “A” + Counter.ToString
and outside the If, i add Counter = Counter + 1
but this only means that it will always write in A3

How do i write the logic so that it will write in the IF sequence as such
Then: write in A2
Else: write in A2
in the next loop
Then: write in A3
Else: write in A3
in the next loop
Then: write in A4
Else: write in A4
so on and so forth till the excel next line item is a blank

Hi @minthodology

If you provide the Excel file for the same and if you explain more in detail then it will be easy to give you the solution

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi Pratik,

Excel example as follows:

image

In this case, i would like to write into the Cell C2, C3, C4

@minthodology

In If Condition, You have to give as

row("ColumnName") = isInRecord

Mark as solution if this helps you

Thanks

Hi,

There is an error saying Option Strict on disallows operands of type Object for operator ‘=’ . Use ‘is’ operator to test for object identity.

image

@minthodology

Oops sorry

row("ColumnName").ToString = isInRecord

Check as above

You can check below post for your reference too

Thanks

@minthodology

What’s the condition you are checking for? What is isInRecord value holds?

Thanks

It holds a Element Exist which is a Boolean

Hi, thanks
now the new error is Option Strict on disallows implicit conversions from 'Strings to ‘boolean’
my isinrecord is a boolean

@minthodology

Can you share your workflow? I didn’t see Element Exist inside the For Each Row? then you will get for element exist for the first row only

Also instead of Counter, you can use Index of the For each to increment

Hope this may helps

Thanks

Hi,

It is inside the For Each Row before the If activity

@minthodology

Fine, Then you can use Index variable as below for increment

Create a Index variable, and remove Counter.ToString and place Index.ToString

Hope this helps you

Thanks

how do i create a index variable?

@minthodology

Just create a variable in index

OR

You can use the counter variable to that index

Thanks

image

Like so?

@minthodology

Yes, any with variable type Int32, You can use your existing counter variable also

Thanks

image
image

Now the error is the Write Cell: The range does not exist

@minthodology

write as below

"C" + (Counter + 2).ToString

Mark as solution if this helps

Thanks