0

我有 3 列 ABC

我需要根据 C 的值将 A 列中的值提取到另一个(E 列)。

如果 C 列没有,则 A 列中的额外值如果 A 列有 2 个相等的值111,则检查 C 中的任何一个是否为是,如果是,则提取该值。如果 C 列都为“否”,则将两者都提取到列表中。

 A     B    C
123   22    NO
111   21    NO
111   22    YES
222   33    NO
222   34    NO

输出

  A    B    C
 123   22   NO
 111   21   YES
 222   33   NO
 222   34   NO
4

2 回答 2

0

尝试这个:

  • 如果 A 列中没有重复项,则复制行
  • 如果在A列中重复,首先取是的,否则取所有否的

    Sub LoopRange()
      Dim rCell As Range
      Dim lCell As Range
      Dim jCell As Range
      Dim rRng As Range
      Set rRng = Sheet1.Range("A1:A5")
      Dim rCntr As Integer
      rCntr = 1
    
      Dim rangelist As String
    
      'loop through main list
      For Each rCell In rRng.Cells
        Dim duplicate As Boolean
        duplicate = False
    
      On Error Resume Next
      Set isect = Application.Intersect(Range(rCell.Address), Range(rangelist))
      If isect Is Nothing Then
        ' loop through rest of list to check for duplicates
        For Each lCell In rRng.Cells
            'Check for duplicates
            If lCell.Value = rCell.Value Then
                'Add duplicate row to list
                If duplicate = False Then
                    rangelist = "A" & lCell.row
                Else
                    rangelist = rangelist & "," & "A" & lCell.row
                End If
                duplicate = True
            End If
        Next lCell
    
        'If a duplicate was found
        If duplicate = True Then
            Dim nRng As Range
            Set nRng = Range(rangelist)
            Dim isNO As Boolean
            isYes = False
            For Each jCell In nRng
                If jCell.Offset(0, 2) = "YES" Then
                    Range(jCell, jCell.Offset(0, 2)).Select
                    Selection.Copy
                    Range("E" & rCntr).Select
                    ActiveSheet.Paste
                    isYes = True
                    rCntr = rCntr + 1
                End If
            Next jCell
    
            'list all no's
            If isYes = False Then
                For Each jCell In nRng
                    Range(jCell, jCell.Offset(0, 2)).Select
                    Selection.Copy
                    Range("E" & rCntr).Select
                    ActiveSheet.Paste
                    rCntr = rCntr + 1
                Next jCell
            End If
        End If
    End If
     Next rCell
    End Sub
    

这就是我得到的

在此处输入图像描述

于 2013-09-18T23:03:35.473 回答
0

你的英语不好,但你想把它放在字段 E 中:

=IF(C1 = "NO",A1,B1)

如果不完全正确,它至少应该为您指明正确的方向。顺便说一句,您可以像这样嵌套 IF 语句:

=IF(C1 = "NO",IF(B1 = "YES",D1,A1),B1)
于 2013-09-18T20:28:04.787 回答