Searching for interior color and borders
I'd like to find the last row that contains any one of the following things:
- Text
- Interior color
- Borders
This construct:
Code:
with wks
lastRow = .Columns(col).Find("*", SearchOrder:=xlByRows, _
LookIn:=xlValues, SearchDirection:=xlPrevious).row
end with
seems to only find text. I can accomplish my goal by looping over each cell in the column, something like (untested):
Code:
Dim i as integer
with wks
for i = 65535 to 1 step -1
if not isEmpty(.cells(i,col)) and .cells(i,col).interior.colorIndex <> xlNone then _
exit for
next i
end with
msgbox("Last row with anything is " + str(i))
I don't know how to tell if there's a border, but in principle I can Google for it, and if I can't find it, ask here, and use it as a third condition in the conditional.
If there a faster or shorter way of doing this?
Thanks!
Re: Searching for interior color and borders
Quote:
I don't know how to tell if there's a border
Does this help?
vb Code:
'Example for cell A1
If Range("A1").BorderAround = True Then
MsgBox "This cell has a border"
End If
Quote:
If there a faster or shorter way of doing this?
Tip: If you loop through all the 65536 cells then excel will be damn slow. Check out "SpecialCells Method" in VBA Help to find the last cell. Then you can combine both to get the desired result...