HIghlight a cell within a Spilled Range, when selected

Skybluekid

Well-known Member
Joined
Apr 17, 2012
Messages
1,226
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a spilled range, when I click a cell in that range, I would like it highlighted. But if a cell is clicked outside the range, the cell would would not highlight. Any ideas would be welcome.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Like this? (Test with a copy)

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  ActiveSheet.UsedRange.Interior.Color = xlNone
  If ActiveCell.HasSpill Then ActiveCell.Interior.Color = vbYellow
End Sub
 
Upvote 0
Solution
@Peter_SSs Thank you for the code.

I have modified it to work within a specific range.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Sheet2.Range("F2:F37").Interior.Color = xlNone
Sheet2.Range("F2:F37").Font.Bold = False
If ActiveCell.HasSpill Then ActiveCell.Interior.Color = vbYellow
If ActiveCell.HasSpill Then ActiveCell.Font.Bold = True
End Sub
 
Upvote 0
Will the only spill range(s) in the worksheet reside in F2:F37?

BTW, no need to prefix any ranges with Sheet2 as I presume that this code will be in the Sheet2 module?
Also, no need to check twice if ActiveCell.HasSpill

Assuming the only spill range(s) would occur in F2:F37 ..

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  With Range("F2:F37")
    .Interior.Color = xlNone
    .Font.Bold = False
  End With
  With ActiveCell
    If .HasSpill Then
      .Interior.Color = vbYellow
      .Font.Bold = True
    End If
  End With
End Sub
 
Upvote 0
Yes the spilled range only lives in that range. Thank you for the updated code and tips.:)
 
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,605
Members
449,174
Latest member
ExcelfromGermany

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