Exit this Sub

Ralph M

Well-known Member
Joined
Apr 16, 2002
Messages
502
Office Version
  1. 2016
Platform
  1. Windows
I have code that puts a boarder around the entire row when a cell is selected, what I would like to do is Exit Sub if another Cell in the Active Row is selected. This is in the WorkSheet SelectionChange Module.
Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Sorry,
No matter which Cell I select, the Code puts a border around the outside of the entire row. Then when I select a different Cell, the border is removed fr the current selection and a new border is crreated around the newley selected Cell. What I want to do is check so that if I select a Cell in the Active Row, Exit Sub. So the Code doesn't run every single time I select a Cell in the same Row.
Does that help?
 
Upvote 0
I'm not sure how to address the Active Row to check if I selected a Cell in the same Row.
This is in the WorkBook SelectionChange Module.
 
Upvote 0
Jon,

If I select "B3", the entire row 3 has a border around it, here is my Code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long
i = Selection.Row

With Cells
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End With

With Range(Cells(i, 1), Cells(i, 256).End(xlToLeft)).Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Range(Cells(i, 1), Cells(i, 256).End(xlToLeft)).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Range(Cells(i, 1), Cells(i, 256).End(xlToLeft)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Range(Cells(i, 1), Cells(i, 256).End(xlToLeft)).Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With

End Sub
 
Upvote 0
OK; B3 gets selected and row 3 gets bordered.

Then D3 is selected and you want the process short-stopped then? Not sure the checking for an existing border's going to save anything ...
 
Upvote 0
Yes, that's it Jon, At lease it won't run the Code everytime I change a Cell in the same Row.
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,566
Members
453,053
Latest member
Kiranm13

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