Excel skip to the next row


#1

Good Morning,
I have searched a see many examples on how to skip to the next cell but not one that skips to the next row.
Using a for loop after reading a range if I encounter a row that contains a specific value in row(0) I want to skip the next row and read its value in cell 1.

Thanks for your help


#2

Under the assumption you’re doing this in excel (sorry if not);

Read the range to the datatable, then at the beginning of each ‘for each row’ loop increment a counter by 1. Note - if you are adding headers to the DT then you should initialize the counter at 1, so that the first row it reads will be recognized as row 2 of the spreadsheet. If you are not adding headers, initialize the counter at 0.
When it finds a matching row, add a break to come out of the loop, and then read cell - “A”+(yourCounter+1).ToString (assuming the value you need to read is in col A).

This will read the cell in the row after the last one processed during the for each loop.


#3

Thanks for the response. The issue is once I break out of the for loop I wont be able to read additonal rows that meet that criteria. I was hoping for a skip line activity:(


#4

I was able to solve using a Boolean

. So if I encounter a row than I set the value to true. The for loop proceeds and if the next row has a value I grab it. If it is null than I skip to the next occurrence of the original condition.

Thanks for your insight:)


Skip some rows in Foreach Row
#5

Please find SkipRow.xaml (10.0 KB). I have used simple comparisons to achieve this.