Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. =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
  2.  
  3. Sub test()
  4. Dim rng1 As Range
  5. Dim rng2 As Range
  6. Set rng1 = Sheets(1).[a1:a10]
  7. Application.ScreenUpdating = False
  8. For Each rng2 In rng1.Cells
  9. If oneCellsDependents(rng2) Then
  10. rng2.Interior.Color = vbRed
  11. Else
  12. rng2.Interior.Color = xlNone
  13. End If
  14. Next
  15. Application.ScreenUpdating = True
  16. End Sub
  17.  
  18. Function oneCellsDependents(rng1 As Range) As Boolean
  19. ' written by Bill Manville
  20. ' With edits from PaulS
  21. ' this procedure finds the cells which are the direct precedents of the active cell
  22. Dim rLast As Range, iLinkNum As Long, iArrowNum As Long
  23. Dim bNewArrow As Boolean
  24. Application.ScreenUpdating = False
  25. rng1.ShowDependents
  26. Set rLast = rng1
  27. iArrowNum = 1
  28. iLinkNum = 1
  29. bNewArrow = True
  30. Do
  31. If oneCellsDependents Then Exit Do
  32. Do
  33. Application.Goto rLast
  34. On Error Resume Next
  35. rng1.NavigateArrow TowardPrecedent:=False, ArrowNumber:=iArrowNum, LinkNumber:=iLinkNum
  36. If Err.Number > 0 Then Exit Do
  37. On Error GoTo 0
  38. If rLast.Address(external:=True) = ActiveCell.Address(external:=True) Then Exit Do
  39. bNewArrow = False
  40. If ActiveCell.Parent.Name = Sheets(2).Name Then
  41. oneCellsDependents = True
  42. Exit Do
  43. End If
  44. iLinkNum = iLinkNum + 1 ' try another link
  45. Loop
  46. If bNewArrow Then Exit Do
  47. iLinkNum = 1
  48. bNewArrow = True
  49. iArrowNum = iArrowNum + 1 'try another arrow
  50. Loop
  51. rLast.Parent.ClearArrows
  52. Application.Goto rLast
  53. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement