簡體   English   中英

Excel-根據另一個列值提取數據

[英]Excel - extracting data based on another column value

我有3列ABC

我需要基於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

您的英語不好,但您想將其放在字段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 

這就是我得到的

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM