我已设置并使用零件编号作为参考的库存表,有一个注明日期的注销表,当它与零件编号匹配时,会进入当前库存表中的公式。
由于人为错误和输入零件编号的错误,我想知道是否使用了注销的值,如果使用了绿色检查或灯光,如果没有使用红色X或灯光。
所以我需要做以下事情:
=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
答案 0 :(得分:0)
This microsoft help可以让您非常接近您的要求。
答案 1 :(得分:0)
此代码:
设置要测试的区域
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