[Excel] Loop rows until Border found
I have virtually no experience manipulating Excel from VB.NET, so consider me a total beginner.
I'm looping through cells in sheets in workbooks in a directory. I'm fine doing this if I know how many columns (which I always know) and rows (which I never know) I need to loop through.
What I need to do is loop through rows until I find a Border - i.e. if I'm on a row that has a Border on the top then stop. I don't want to loop through any more rows.
Currently I'm simply looping like this and frankly don't know where to go from here.
How can I loop through my rows until I find a border? How shall my loop look? Thanks!
vb.net Code:
For i As Integer = 2 To 5 ' How many rows starting at row 2? Who knows?
For j As Integer = 1 To 10 Step 1 ' Always this many columns.
toSheet.Cells(i, j) = fromSheet.Cells(i, j + 1)
Next j
Next i
Re: [Excel] Loop rows until Border found
vb Code:
For i As Integer = 2 To 5 ' How many rows starting at row 2? Who knows?
if not cells(i,1).Borders(xlEdgeTop).ColorIndex = xlnone then exit for ' checks column 1 for any top border
For j As Integer = 1 To 10 Step 1 ' Always this many columns.
toSheet.Cells(i, j) = fromSheet.Cells(i, j + 1)
Next j
Next i
you could alternatively check the the line style, for appropriate values