|
-
Apr 25th, 2008, 08:57 PM
#1
Thread Starter
Registered User
[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
-
Apr 25th, 2008, 10:47 PM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|