View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default optimize coding on named range

One way -

Sub test()
Dim bGotCel As Boolean
Dim rwFirst As Long, rwLast As Long
Dim r As Long, c As Long
With Range("second_column")
rwFirst = .Row
c = .Column
End With

rwLast = Cells.SpecialCells(xlLastCell).Row

For r = rwFirst To rwLast
With Cells(r, c).Borders(xlEdgeBottom)
If .Weight = xlMedium And .LineStyle = xlContinuous Then
bGotCel = True
Exit For
End If
End With
Next

If bGotCel Then
Range(Cells(r, c), Range("second_column")).Name = "second_column"
Else
MsgBox "xlEdgeBottom xlMedium xlContinuous not found"
End If

Range("second_column").Select ' only if sure on active sheet

End Sub

Assumes "second_column" starts as a single named cell and hopefully a cell
with the border formats you are looking for exists somewhere below in same
column.

Regards

"Dantz" wrote in message
ups.com...
is there a better way to do this?

Range("second_column").Select
Do While Not ActiveCell.Borders(xlEdgeBottom).Weight = xlMedium And Not
ActiveCell.Borders(xlEdgeBottom).LineStyle = xlContinuous
ActiveCell.Offset(1, 0).Select
Loop
Range(ActiveCell, Range("second_column")).Name= "second_column"

please help how to do this better..
in my named range I don't know how to get its column to check
for a specific cell outside(below) of the range