Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =IF cell A1 is used in any formula in Sheet1!B:B THEN mark with green check, IF cell A1 is not used in any formula in Sheet1!B:B THEN mark it with a red X
- Sub test()
- Dim rng1 As Range
- Dim rng2 As Range
- Set rng1 = Sheets(1).[a1:a10]
- Application.ScreenUpdating = False
- For Each rng2 In rng1.Cells
- If oneCellsDependents(rng2) Then
- rng2.Interior.Color = vbRed
- Else
- rng2.Interior.Color = xlNone
- End If
- Next
- Application.ScreenUpdating = True
- End Sub
- Function oneCellsDependents(rng1 As Range) As Boolean
- ' written by Bill Manville
- ' With edits from PaulS
- ' this procedure finds the cells which are the direct precedents of the active cell
- Dim rLast As Range, iLinkNum As Long, iArrowNum As Long
- Dim bNewArrow As Boolean
- Application.ScreenUpdating = False
- rng1.ShowDependents
- Set rLast = rng1
- iArrowNum = 1
- iLinkNum = 1
- bNewArrow = True
- Do
- If oneCellsDependents Then Exit Do
- Do
- Application.Goto rLast
- On Error Resume Next
- rng1.NavigateArrow TowardPrecedent:=False, ArrowNumber:=iArrowNum, LinkNumber:=iLinkNum
- If Err.Number > 0 Then Exit Do
- On Error GoTo 0
- If rLast.Address(external:=True) = ActiveCell.Address(external:=True) Then Exit Do
- bNewArrow = False
- If ActiveCell.Parent.Name = Sheets(2).Name Then
- oneCellsDependents = True
- Exit Do
- End If
- iLinkNum = iLinkNum + 1 ' try another link
- Loop
- If bNewArrow Then Exit Do
- iLinkNum = 1
- bNewArrow = True
- iArrowNum = iArrowNum + 1 'try another arrow
- Loop
- rLast.Parent.ClearArrows
- Application.Goto rLast
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement