Question: Right now when a user selects a cell, an associated cell is highlighted by adding a medium thickness border. This is done for a calendar of times. 

For example, when user clicks D4 it must add border to B5 and when user unselects D4 it must un-border B5: 

![](https://puu.sh/dhJRQ/dc3e0112d2.png)

The code for this is as follows and it works:

```
If Not Intersect(Target, Range("$D$4")) Is Nothing Then
    Range("$B$5").Borders(xlEdgeBottom).Weight = xlMedium
    Range("$B$5").Borders(xlEdgeTop).Weight = xlMedium
    Range("$B$5").Borders(xlEdgeLeft).Weight = xlMedium
    Range("$B$5").Borders(xlEdgeRight).Weight = xlMedium
Else
    Range("$B$5").Borders(xlEdgeBottom).Weight = xlThin
    Range("$B$5").Borders(xlEdgeTop).Weight = xlThin
    Range("$B$5").Borders(xlEdgeLeft).Weight = xlThin
    Range("$B$5").Borders(xlEdgeRight).Weight = xlThin
End If

```

The trouble with this is that it runs for 30 cells every time any cell is selected. This means that it even if nothing has changed, all 30 cells have their formatting checked and reset, or, all 30 "else" blocks run every time unnecessarily. This is only a few hundred commands but it definitely lags things up quickly. Is there a way to clean this up? Otherwise it's going to need 30 cells \* 11 lines of code which seems excessive.

Answer: 
You don't have to call out the borders individually:

```
Dim wt as Long

If Not Intersect(Target, Range("$D$4")) Is Nothing Then
    wt = xlMedium
Else
    wt = xlThin
End If

Range("$B$5").Borders.Weight = wt

```

It's not too clear how you're capturing the selection, but a faster approach might be to set the whole range to `xlThin` and then deal with the selected cells.
This is my best guess at what you want to do. You give only one example, so it's impossible to tell for sure, but I think you want a thick border on the cell one below and two to the left of the selected cell. 

```
'Make them all thin
Range("B4:B10").Borders.Weight = xlThin

If Not Intersect(Target, Range("D4:D9")) Is Nothing Then
    'Make medium border on cell one below and two to the right
    Target.Offset(1,-2).Borders.Weight = xlMedium
End If

```

This code belongs in the `Worksheet_SelectionChange` event. (Presumably you already know this.)

![enter image description here](https://i.stack.imgur.com/AMyxL.png)

You did right to ask a question; there is almost never any reason to copy-paste code multiple times. If you find yourself doing that, then you're probably missing a much easier way of doing things.