Hi,
I am trying to create a macro to put a top border on the row when a selection in a row changes. There are only 3 selections so will be 2 lines per worksheet. So, Column C will be
Apples
Apples
Apples
Oranges
Oranges
Bananas
Bananas
Bananas
Bananas
I would like to have a line between Apples and Oranges and Oranges and Bananas, that is, whenever the value in the column changes. My code thus far is:
Any help will be much appreciated!!
I am trying to create a macro to put a top border on the row when a selection in a row changes. There are only 3 selections so will be 2 lines per worksheet. So, Column C will be
Apples
Apples
Apples
Oranges
Oranges
Bananas
Bananas
Bananas
Bananas
I would like to have a line between Apples and Oranges and Oranges and Bananas, that is, whenever the value in the column changes. My code thus far is:
Code:
Sub Line()
Dim M As Long, i As Long
M = Range("C4:C2000")
For i = 0 To M
If Range("C" & i + 4) = "Apples" Then i = i + 1
If Range("C" & (i - 1) + 4) = "Apples" And Range("C" & i + 4) = "Oranges" Then
Range("C" & (i - 1) + 4).Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Next i
If Range("C" & i + 4) = "Oranges" Then i = i + 1
If Range("C" & (i - 1) + 4) = "Oranges" And Range("C" & i + 4) = "Bananas" Then
Range("C" & (i - 1) + 4).Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End If
End Sub
Any help will be much appreciated!!