Write cell in excel if row contains course name and specific date

Hello,

How do I loop through a excel sheet and write cell if that rows contain the course name and date i want and skip/go to the next row if it does not fulfill my requirements.
Been trying for each loop and putting if else in the for each but its not working.

Thank you :slight_smile:

2 Likes

Hi @Magpie444

Welcome to the community!!

I suppose you know the column where you want to write in the cell.

So, let’s follow the below steps.

  • Have a int variable and assign it to 1 - this will be used within the loop to increment in each iteration to figure out the excel row we want to write in.
  • Use Read Range to read the excel to a datatable
  • use a for each row loop to loop through the data table.
  • within the loop, have a if condition to check whether it has the course name and date

Row("ColumnName").ToString.Contains(Course name variable)
Or
Use this if its empty when course name is not available
String.IsNullOrEmpty(row("ColumnName").ToString)

Same goes with the date

  • now in the if condition, place the write cell activity to write the value in the desired cell.
    Use the integer variable we declared to find the row. So in write cell, for the cell number configure it as follows
    β€œD” + rowNumberVariable.ToString
  • now outside the if condition, but inside the loop, place an assign activity and increment the row number variable by 1

This will work for you :slight_smile:

4 Likes

Hi thanks for your help :slight_smile: i have tried what u told me to do but its still not working it doesnt seem to be picking up the row. And the rowNumberVariable is not increment.

1 Like

@Magpie444

You specified condition like this:
writeRow(β€œ1”)

Here 1 is the Column name or Column Index ?

If it is Column Index then it should be like this:

writeRow(1).ToString

2 Likes

@Magpie444

Along with the concern of @lakshman I also would like to see what you have in your Cell property of the write cell activity

2 Likes

hi,
1 is the column name

1 Like

@Magpie444

Before IF condition, print this value using message box and check once.

writeRow(β€œ1”).ToString

image

Hi it is running through all the rows from that column

Hi,
I solved my issue the continue activity was causing the problem.

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