我有3列A B C
我需要根据C的值将A列中的值提取到另一个(E列)。
如果列C为否则列A中的额外值
如果列A具有2个相等的值111
,则检查C中的任何一个是否为是,如果是,则提取该值。
如果C列都是NO,则在列表中提取两者。
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
答案 0 :(得分:0)
你的英语不好但是你想把它放在E:
=IF(C1 = "NO",A1,B1)
如果不完全相同,它至少应该指向正确的方向。顺便说一下,你可以嵌套这样的IF语句:
=IF(C1 = "NO",IF(B1 = "YES",D1,A1),B1)
答案 1 :(得分:0)
试试这个:
如果在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
这就是我得到的