Showing posts with label Excel Borders. Show all posts
Showing posts with label Excel Borders. Show all posts

Saturday, June 26, 2010

Draw border lines around cells with common values

How to draw borders around cells with common values


Sub Draw_border_for_common_items_in_row()

Sheets("Top CTDs").Select
LC1 = ActiveSheet.UsedRange.SpecialCells(xlLastCell).Column
LR1 = ActiveSheet.UsedRange.SpecialCells(xlLastCell).Row

For i = 1 To LC1
temp = Cells(2, i).Value
ro = 2
    For j = 2 To LR1
        If Cells(j, i).Value <> temp Then
            Range(Cells(ro, i), Cells(j - 1, i)).Select
            Selection.BorderAround Weight:=xlThin
            ro = j
            temp = Cells(j, i).Value
           
        End If
       
    Next j
Next i

End Sub