Vba 计数将列中的单元格重复到最后一行
我想将列中的重复单元格计数到最后一行,我可以将所有行计数到最后一行,但无法计算重复部分 如果我找到了解决方案,我会继续查找并发回 编辑:更改为以下“我得到错误”“类型不匹配”Vba 计数将列中的单元格重复到最后一行,vba,excel,Vba,Excel,我想将列中的重复单元格计数到最后一行,我可以将所有行计数到最后一行,但无法计算重复部分 如果我找到了解决方案,我会继续查找并发回 编辑:更改为以下“我得到错误”“类型不匹配” 子联系人姓名22() 暗淡的光线和长的一样 不算长 第(2)页。选择 lRow=单元格。查找(“*”,[A1],.xlByColumns,xlPrevious)。行 count=“=SUMPRODUCT((E2&lRow)”)/COUNTIF(E2&lRow&“”)-(COUNTIF(E2&lRow&“”)=1) MsgB
子联系人姓名22()
暗淡的光线和长的一样
不算长
第(2)页。选择
lRow=单元格。查找(“*”,[A1],.xlByColumns,xlPrevious)。行
count=“=SUMPRODUCT((E2&lRow)”)/COUNTIF(E2&lRow&“”)-(COUNTIF(E2&lRow&“”)=1)
MsgBox计数
端接头
以下是一个宏示例:
Sub CountDuplicates()
Dim N As Long, cl As Collection
Dim dCount As Long, V As Variant
N = Cells(Rows.count, 1).End(xlUp).Row
Set cl = New Collection
dCount = 0
For i = 1 To N
V = Cells(i, 1).Value
On Error Resume Next
If V <> "" Then
cl.Add V, CStr(V)
If Err.Number = 0 Then
Else
Err.Number = 0
dCount = dCount + 1
End If
End If
Next i
MsgBox "There are " & dCount & " duplicates"
End Sub
Sub countreplicates()
尺寸N等于长度,cl等于集合
长度为Dim D计数,变量为V
N=单元格(Rows.count,1)。结束(xlUp)。行
Set cl=新集合
dCount=0
对于i=1到N
V=单元格(i,1)。数值
出错时继续下一步
如果V“那么
第五条添加第五条,CStr(五)
如果Err.Number=0,则
其他的
错误号=0
dCount=dCount+1
如果结束
如果结束
接下来我
MsgBox“有”&d计数和“重复”
端接头
请尽量避免将代码作为答案。提供一些上下文,或澄清您的解决方案解决/实现了什么。谢谢:)
Sub CountDuplicates()
Dim N As Long, cl As Collection
Dim dCount As Long, V As Variant
N = Cells(Rows.count, 1).End(xlUp).Row
Set cl = New Collection
dCount = 0
For i = 1 To N
V = Cells(i, 1).Value
On Error Resume Next
If V <> "" Then
cl.Add V, CStr(V)
If Err.Number = 0 Then
Else
Err.Number = 0
dCount = dCount + 1
End If
End If
Next i
MsgBox "There are " & dCount & " duplicates"
End Sub
Sub ContactName22()
'Declaring
Dim Sheets(2)As Worksheet
Set Sheets(2)= ThisWorkbook.Sheets("Sheets(2)")
Dim x As Long
Dim count As Long
Dim lastRow As Long
Dim lastColumn As Long
Sheets(2).Select
lastRow = dbSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastColumn = dbSheet.Cells(1, Columns.Count).End(xlToLeft).Column
For y = 1 to LastColumn 'Looping through the columns until last column
For x = 2 To lastRow 'Looping through the rows until last row
if ...... 'whatever condition that applies in your case
Then
'do something else here
count = count+1 'counting how many times has found duplicates based on the condition of `if` statment.
End if
Next x
Next y
Cells(lastRow+1,2).Value=count 'assigning the value of the counter
End Sub