X
xenovah
I'm using this code to look for cells with borders turned on. If I
replace the code with .Font or .Interior.ColorIndex properties, it
finds the appropriate cells. However when I change the code to look for
..Borders properties, there aren't any cells found.
Sub test()
'select cells with thick borders only
Dim firstcell As Range
Dim foundcell As Range
Dim allcells As Range
'specify the formatting to look for
With Application.FindFormat
.Clear
' .Font.Bold = True
' .Interior.ColorIndex = 6 'yellow
' .Font.Name = "Courier"
.Borders.LineStyle = xlEdgeTop
End With
'look for the first matching cell
Set firstcell = Cells.Find(what:="", searchformat:=True)
'if nothing was found, then exit
If firstcell Is Nothing Then
MsgBox "No matching cells found"
Exit Sub
End If
MsgBox "First cell is column: " & firstcell.Column & " row: " &
firstcell.Row
'initialize all cells
'Set allcells = firstcell
'Set foundcell = firstcell
'loop until the first cell is found again
'Do
' Set foundcell = Cells.FindNext(after:=foundcell)
' Set allcells = Union(foundcell, allcells)
' If foundcell.Address = firstcell.Address Then Exit Do
'Loop
'select the found cells and inform the user
'allcells.Select
'MsgBox "Matching cells found: " & allcells.Count
End Sub
I'd appreciate any input.
Thanks.
replace the code with .Font or .Interior.ColorIndex properties, it
finds the appropriate cells. However when I change the code to look for
..Borders properties, there aren't any cells found.
Sub test()
'select cells with thick borders only
Dim firstcell As Range
Dim foundcell As Range
Dim allcells As Range
'specify the formatting to look for
With Application.FindFormat
.Clear
' .Font.Bold = True
' .Interior.ColorIndex = 6 'yellow
' .Font.Name = "Courier"
.Borders.LineStyle = xlEdgeTop
End With
'look for the first matching cell
Set firstcell = Cells.Find(what:="", searchformat:=True)
'if nothing was found, then exit
If firstcell Is Nothing Then
MsgBox "No matching cells found"
Exit Sub
End If
MsgBox "First cell is column: " & firstcell.Column & " row: " &
firstcell.Row
'initialize all cells
'Set allcells = firstcell
'Set foundcell = firstcell
'loop until the first cell is found again
'Do
' Set foundcell = Cells.FindNext(after:=foundcell)
' Set allcells = Union(foundcell, allcells)
' If foundcell.Address = firstcell.Address Then Exit Do
'Loop
'select the found cells and inform the user
'allcells.Select
'MsgBox "Matching cells found: " & allcells.Count
End Sub
I'd appreciate any input.
Thanks.