我 Excel中的3列:
A)客户编号
B)客户编号已验证
C)验证状态
Client NumbersClient Numbers Verified Verification Status
999999999999/98989691699 999999999999 Verified
888888888888/58555555555 111111111111
454545454545/69412999999 888888888888 Verified
22222222222/111111555555 YYYYYYYYYYYY
888888888888/56998165446
我正在尝试创建一个宏,其中包含以下内容:
a)比较A列和A列。 B仅关于左12个字符并查找重复项
b)如果发现重复,则清除(不删除)左12字符中的内容,重复值在列B中找到
c)输入测试"已验证"在列C中与列A相同的行号
我发现很多宏比较和删除内容但非比较有限数量的字符并按我的要求进行。我尝试混合一些宏,但由于我的知识,它没有加起来。请帮助。
答案 0 :(得分:0)
编辑
您可以尝试以下代码:
Option Explicit
Sub main()
Dim cell As Range, f As Range
With Worksheets("Clients") '<--| reference "Clients" worksheet (change "Clients" to your actual worksheet name)
With .Range("A1", .Cells(.rows.Count, "A").End(xlUp)) '<--| reference its column "A" cells from row 1 down to last non empty one
For Each cell In .Cells '<--| loop through referenced cells
Set f = .Offset(, 1).Find(what:=Left(cell.Text, 12) & "*", LookIn:=xlValues, lookat:=xlWhole) '<--| look for current cell first twelve charachters string in adjacent column cells first 12 characters content
If Not f Is Nothing Then '<--| if any match has been found...
f.ClearContents '<--|... clear column "B" cell that matched the search...
cell.Offset(, 2).Value = "Verified" '<--|... and write "Verified" in column "C" current cell row
End If
Next cell
End With
End With
End Sub