简体   繁体   English

Excel-在A列中找到一个小于或等于4倍的值并在B列中打印

[英]Excel - find a value in column A that appears less than or equal to 4 times and print in column B

I have a list of usernames sorted alphabetically in column A, with some appearing numerous times. 我在A列中按字母顺序排列了一个用户名列表,其中一些出现了无数次。 I want to prnt the username in column B if it appears less than or equal to 4 times. 如果用户名出现少于或等于4次,我想打印B列中的用户名。

Do I need an array to go through all the different username values in the column to find the ones that appear less than or equal to 4 times? 我是否需要一个数组来遍历列中所有不同的用户名值,以查找出现少于或等于4次的值?

Consider: 考虑:

Sub dural()
    Dim A As Range, B As Range, v As String, K As Long
    Set A = Intersect(Range("A:A"), ActiveSheet.UsedRange)
    Set B = Range("B:B")

    K = 1

    With Application.WorksheetFunction
    For Each aa In A
        v = aa.Value
            If v <> "" Then
                If .CountIf(A, v) <= 4 Then
                    If .CountIf(B, v) = 0 Then
                        Cells(K, "B").Value = v
                        K = K + 1

                    End If
                End If
            End If
    Next aa
    End With
End Sub

在此处输入图片说明

Add a helper column and place the following formula in the second row: 添加一个帮助器列,并将以下公式放在第二行中:

=IF(AND(COUNTIF(A:A,A2)<=4,COUNTIF($A$2:A2,A2)=1),MAX($B$1:B1)+1,"")

And copy down: 并抄下来:

在此处输入图片说明

At this point you can filter on the non Blank Cells and copy them to another range. 此时,您可以过滤非空白单元格并将其复制到另一个范围。

If you want to use a formula to get the list then Put this in another column row 2: 如果要使用公式来获取列表,则将其放在另一列的第2行中:

=IFERROR(INDEX(A:A,MATCH(ROW(1:1),B:B,0)),"")

And copy down. 并抄下来。

在此处输入图片说明

No need for helper columns or VBA, just a bit of finely-tuned IF functions :) 不需要辅助列或VBA,只需调整一下IF函数即可:)

=IF(COUNTIFS(BE:BE,BE2)<=4,IF(COUNTIFS($BE$1:BE2,BE2)=1,BE2,"0"),"0")

^Here, BE is where all your data is, starting on Row 2 ^在这里,BE是您所有数据的存放地,从第2行开始

What it does: 它能做什么:

  1. If the Name appears 4 or fewer times, 如果名称出现4次或以下,

  2. If this is the first time the Name appears in the column 如果这是第一次,“名称”将出现在列中

  3. Print the Name 打印名称
  4. (Otherwise insert 0) (否则插入0)

To remove the 0 values ie empty rows: 要删除0值,即空行:

  1. Paste over the formula with the same column as values (this is so you can..) 将公式粘贴到与值相同的列上(这样就可以..)
  2. .. Replace All ( Ctrl-H ) "0"s with nothing "" (so that you can..) .. Replace AllCtrl-H )将“ 0”替换为“”(以便可以..)
  3. .. Select the blank rows using Go To ( Ctrl-G ) > Special > Blanks ..使用Go ToCtrl-G> Special > Blanks来选择空白行
  4. Delete (Shift Cells Up) 删除(向上移动单元格)

You can also simply Filter out the Blank/0 values 您也可以简单地过滤出Blank / 0值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 洗牌列在 Excel 但 ea。 值出现的次数相等 - Shuffle column in Excel but ea. value appears equal amount of times Excel 使用 SUMPRODUCT 查找值在列和 python 中出现的次数 - Excel using SUMPRODUCT to find number of times a value appears in a column and in python Excel计数A列中的单元格小于B列中的相应单元格的范围内的次数 - Excel Count number of times in range that cells in column A are less than corresponding cell in column B 如果某列中每10个单元格中出现的值少于3次,则用另一个值替换这些值 - If a value appears less than 3 times in every 10 cells of a column then replace these values with another value 如何在Excel中查找A1和B1之间的两个小于或等于10的差值 - How to find two difference number values between A1 and B1 less than or equal to 10 value in Excel excel总和列,如果值x在A或B列中且A不等于B - excel sum column if value x is in column A or B and A does not equal B 如果列值连续重复少于3次,则创建Excel宏以删除行 - Creating an Excel Macro to delete rows if a column value repeats consecutively less than 3 times INDEX / MATCH在Excel中查找小于或等于范围内的值 - INDEX/MATCH to find value less than or equal to in range in Excel Excel计数值在列中出现的次数(如果该行唯一) - Excel count number of times a value appears in column, if unique to the row EXCEL - 在 A 列中的值范围内查找 B 列中是否存在值 - EXCEL - Find if value exists in column B in the range of a value in column A
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM