Highlight cells having no dependents

Hiiamsachin

New Member
Joined
Jan 6, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
i need a vba code that would highlights cells already in selection before running the code that has no dependents across the entire sheets in the workbook. It would be of great help to me.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
It is a bit sketchy but do the work. You may run Sub test() for testing:
VBA Code:
Dim selections As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Set selections = Nothing 'Delete this line if you want the previous selections also
  If selections Is Nothing Then
    Set selections = Target
  Else
    Set selections = Union(selections, Target)
    End If
End Sub
Sub test()
  selections.Interior.ColorIndex = 6
End Sub
 
Upvote 0
Can you describe what you need again?
Sure. I want a macro that would highlight cells that i have selected which have one or more dependent cell in the workbook. If i have selected some cells in excel and any other cell in the workbook is dependent on that cell then the selected cell needs to be highlighted.
 
Upvote 0
Oh, ok.
Paste this code into your sheet. Must do the job:
VBA Code:
Dim oldRange As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Application.EnableEvents = False
  If Not oldRange Is Nothing Then oldRange.Interior.Color = xlNone
  On Error Resume Next
  Dim myRange As Range, c As Range
  Set myRange = Target

  For Each c In myRange.Precedents
    Set myRange = Union(myRange, c)
  Next
  If myRange.Count > 1 Then
    myRange.Interior.ColorIndex = 6
    Set oldRange = myRange
  End If
  Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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