用exce从各列数据中l选出相同的项,在另一列中排列并计算出相同项出现次数.

1个回答

  • 用VBA代码可方便的统计出来重复数据

    用鼠标点击当前工作表下方的标签名,在右键菜单中选“查看代码”,会打开VBA窗口,然后把下面代码复制到打开的窗口中,在VBA窗口中按键盘再上方的F5键,就执行这个代码即可得到统计结果.

    Sub 统计()

    y1 = 1 '开始列为A列(在EXCEL中,A列的列号为1)

    y2 = 4 '结束列为D列(在EXCEL中,D列的列号为4)

    x = 2

    n1 = 255 '辅助列

    n2 = 7 '结果显示列(7代表G列,可改为实际列号)

    For i = y1 To y2

    s = Cells(65536, y1).End(xlUp).Row

    Range(Cells(1, i), Cells(s, i)).Copy Cells(x, n1)

    x = x + s

    Next

    Cells(1, n1) = "数据"

    Columns(n1).AdvancedFilter 2, , Cells(1, n2), 1

    s1 = Cells(65536, n2).End(xlUp).Row

    For i = 2 To s1

    Cells(i, n2 + 1) = WorksheetFunction.CountIf(Columns(n1), Cells(i, n2))

    Next

    Columns(n1) = ""

    End Sub