今天项目组的一个同事问我如何快速的找到一个Excel中第3列和第5列的值完全重复的值,我想了想虽然Excel中自带查找重复值的功能,但是好像只能对同一列进行比较,所以就写了一个VBA进行处理,VBA非常简单,但效果不错. Sub FindDuplicatesInColumn() Dim lastRow As Long Dim matchFoundIndex As Long Dim iCntr As Long lastRow = ' 初始化临时列, 第7列用来存放结果,第8列将3 5两列的值拼接起
Function findAndCopy(srcFile As String, destFile As String, cmdFile As String) Dim WSH As Object, wExec As Object, result Dim val, n Dim i As Integer Dim sFile As Object, Fso As Object Dim cmdStr As String Set WSH = CreateObject("WScript.Shell")
1.判断列内是否有重复值: Dim arrT As Range Dim rng As Range Set arrT = Range("A:A")'判读A列单元格 For Each rng In arrT If rng = Empty Then'如果单元格为空就退出循环,否者循环65535次 Exit For End If k = Application.CountIf(arrT, rng)’用CountIf函数扫描出重复值,跟excel的CountIF函数一样 If k > 1