ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find Cells with Specific Format (https://www.excelbanter.com/excel-programming/415630-find-cells-specific-format.html)

Jim Parsells

Find Cells with Specific Format
 
I am trying to find cells in a specific range with a specific Border
configuration. This should be simple, but the following code does not work.
It finds the first such cell OK, but then proceeds to find only empty cells
with no borders. This is with Office Pro 2003.

Sub FindFirstLine()
Worksheets("Sheet1").Activate
ActiveSheet.Range("A:A").Select
Application.FindFormat.Clear
With Application.FindFormat.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection
Set c = .Find(What:="", After:=ActiveCell, LookIn:=xlFormulas,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=True)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Debug.Print c.Address; Tab; c.Value
Set c = .FindNext(c)
If c Is Nothing Then Exit Do
Loop While c.Address < firstAddress
End If
End With
End Sub

Any help will be appreciated.
--
Jim Parsells

Jim Parsells

Find Cells with Specific Format
 
Never mind. I found the answer in this forum by Dave Peterson dated 4/27/08
in reply to msg losing Application.FindFormat.Num...
Thanks Dave.
--
Jim Parsells


"Jim Parsells" wrote:

I am trying to find cells in a specific range with a specific Border
configuration. This should be simple, but the following code does not work.
It finds the first such cell OK, but then proceeds to find only empty cells
with no borders. This is with Office Pro 2003.

Sub FindFirstLine()
Worksheets("Sheet1").Activate
ActiveSheet.Range("A:A").Select
Application.FindFormat.Clear
With Application.FindFormat.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection
Set c = .Find(What:="", After:=ActiveCell, LookIn:=xlFormulas,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=True)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Debug.Print c.Address; Tab; c.Value
Set c = .FindNext(c)
If c Is Nothing Then Exit Do
Loop While c.Address < firstAddress
End If
End With
End Sub

Any help will be appreciated.
--
Jim Parsells



All times are GMT +1. The time now is 06:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com