2

我已经设置了使用零件号作为参考的库存表,当它与零件号匹配时,有一个过时的注销表进入当前库存表的公式。

由于人为错误和输入部件号的错误,我想知道是否使用了被注销的值,如果使用了绿色检查或灯,如果未使用,则可能带有红色 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
4

2 回答 2

0

这个微软帮助可以让你非常接近你的要求。

于 2012-09-12T17:02:22.587 回答
0

这段代码:

  • 测试第一张工作表的 A1:A10 中的每个单元格是否直接依赖于第二张工作表(需要进一步细化以测试是否存在其他工作表上的中间参考)
  • 如果存在依赖于 sheet2,则将这些单元格着色为红色,否则清除内部格式

设置要测试的区域

    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
于 2012-09-13T03:39:38.593 回答