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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,779
Messages
6,174,492
Members
452,567
Latest member
ONEIL290

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