How can I use VBA to highlight the cell 10 rows under the one the user clicks?

sethspearman

New Member
Joined
Apr 15, 2010
Messages
11
Hello,

I want to highlight (apply a bold format) around the cell that is 10 cells under the one my user just clicked. I know the vba for applying the formatting. Here is what I don't know how to do.

I only want this to happen if the user clicks on a certain named range. Pseudo code would be
Code:
If userclickedCell is in myNamedRange then
    'highlight 10 rows down.
End If

Sub HighlightCell(rowsDown as integer)
  'format the borders of that cell.
End Sub

The other trick is that I want to I want to undo it when the user clicks on another cell. So only one cell is highlighted at a time. When the user clicks anywhere outside of the named range then the bold formatting is removed.

Seth
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Maybe something like this?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Application.Intersect(ThisWorkbook.Names("Your_Range").RefersToRange, Target) Is Nothing Then
        Target.Offset(10, 0).Font.Bold = True
    End If
End Sub
 
Last edited:
Upvote 0
Try this.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
    If Target.Count > 1 Then Exit Sub
 
    If Not Application.Intersect(Range("Your_Range"), Target) Is Nothing Then
        Range("Your_Range").Offset(10).Borders.LineStyle = xlNone
        Target.Offset(10, 0).BorderAround xlContinuous, xlThick, xlColorIndexAutomatic
    Else
        Range("Your_Range").Offset(10).Borders.LineStyle = xlNone
    End If
 
End Sub
 
Upvote 0

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