Please help with borders - VBA

harrycosh

New Member
Joined
Feb 27, 2009
Messages
25
I have the following macro, which applies a line where the text "Change" appears in column EE, and an ID number in column EF. It is fine if the "Change" text has more than a 3 row gap but if the text is in the row beneath it does not apply the line, or apply on the 2nd occurance. What am I doing wrong?

Code:
Sub ApplyingBorders()
Dim LSearchRow As Integer
 
On Error GoTo Err_Execute
'Start search in row 1
LSearchRow = 1
While Len(Range("EF" & CStr(LSearchRow)).Value) > 0
 
If Range("EE" & CStr(LSearchRow)).Value = "Change" Then
 
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 15
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
 
'Move counter to next row
LSearchRow = LSearchRow + 1
'Go back to Sheet1 to continue searching
Sheets("Sheet1").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A3
Application.CutCopyMode = False
Range("A3").Select
MsgBox "Lines have been applied"
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub

Thanks
 
Last edited by a moderator:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top