Vba Excel-基于另一列值提取数据
我有3列A、B、C 我需要根据C的值将A列中的值提取到另一列(E列) 如果列C为否,则列A中的额外值 如果A列有两个相等的值Vba Excel-基于另一列值提取数据,vba,excel,excel-formula,excel-2010,Vba,Excel,Excel Formula,Excel 2010,我有3列A、B、C 我需要根据C的值将A列中的值提取到另一列(E列) 如果列C为否,则列A中的额外值 如果A列有两个相等的值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
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
你的英语不好,但你想把它放在字段E中吗:
=IF(C1 = "NO",A1,B1)
如果不完全正确,它至少应该为你指明正确的方向。顺便说一句,您可以嵌套这样的IF语句:
=IF(C1 = "NO",IF(B1 = "YES",D1,A1),B1)
试试这个:
- 如果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
B1怎么可能是
是的
B列有数字。这是一个例子,可以让你找到正确的方向。(教人钓鱼)