EXCEL中避免同一列及相邻列中出现重复数据[原创]
2010-06-25 10:27
253 查看
宏代码如下:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) '检测相邻两列时,先检测右边再检测左边
Dim RC
Dim RCR As String
Dim i As Long
RCR = ""
If Split(ActiveCell.Address, "$")(2) = "1" Then Exit Sub '选中第一行时不执行本SUB
'检查同一行是否有相同数据(左右相邻的两个单元格)
Select Case Split(ActiveCell.Address, "$")(1)
Case "A"
If Range("B" & Split(ActiveCell.Address, "$")(2) - 1).Value = Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Value And Range("A" & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range("B" & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = RGB(200, 160, 35)
Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Value & "与单元格" & Range("B" & Split(ActiveCell.Address, "$")(2) - 1) & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range("B" & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Value = ""
Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Select
Exit Sub
End If
End If
Case "Z"
If Range("Y" & Split(ActiveCell.Address, "$")(2) - 1).Value = Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Value And Range("Z" & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range("Y" & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = RGB(200, 160, 35)
Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Value & "与单元格" & Range("Y" & Split(ActiveCell.Address, "$")(2) - 1) & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range("Y" & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Value = ""
Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Select
Exit Sub
End If
End If
Case Else
If ActiveCell.Column > 26 Then Exit Sub '最大为Z列(Z的ASCII码为128),超出范围则不处理
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & Split(ActiveCell.Address, "$")(2) - 1).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & Split(ActiveCell.Address, "$")(2) - 1 & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
RCR = CStr(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1)
End If
End If
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & Split(ActiveCell.Address, "$")(2) - 1).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & Split(ActiveCell.Address, "$")(2) - 1 & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
RCR = CStr(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1)
End If
End If
If RCR <> "" Then Range(RCR).Select: RCR = "": Exit Sub
End Select
If Split(ActiveCell.Address, "$")(2) = 1 Then Exit Sub '活动单元格是最顶上的单元格时退出SUB
For i = 1 To (Split(ActiveCell.Address, "$")(2) - 2)
'检查同一列是否有相同的数据
If Range(Split(ActiveCell.Address, "$")(1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Split(ActiveCell.Address, "$")(1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Split(ActiveCell.Address, "$")(1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Split(ActiveCell.Address, "$")(1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Select
Exit Sub
End If
End If
'检查相邻列是否存在相同数据(相同行之前的行)
Select Case Asc(Split(ActiveCell.Address, "$")(1))
Case Asc("A") '输入A列时
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Select
Exit Sub
End If
End If
Case Asc("Z") '输入Z列时
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Select
Exit Sub
End If
End If
Case Else 'A-Z中间区段
If ActiveCell.Column > 26 Then Exit Sub '最大为Z列(Z的ASCII码为128),超出范围则不处理
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
RCR = CStr(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1)
End If
End If
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
RCR = CStr(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1)
End If
End If
If RCR <> "" Then Range(RCR).Select: RCR = "": Exit Sub
End Select
Next i
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range) '检测相邻两列时,先检测右边再检测左边
Dim RC
Dim RCR As String
Dim i As Long
RCR = ""
If Split(ActiveCell.Address, "$")(2) = "1" Then Exit Sub '选中第一行时不执行本SUB
'检查同一行是否有相同数据(左右相邻的两个单元格)
Select Case Split(ActiveCell.Address, "$")(1)
Case "A"
If Range("B" & Split(ActiveCell.Address, "$")(2) - 1).Value = Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Value And Range("A" & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range("B" & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = RGB(200, 160, 35)
Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Value & "与单元格" & Range("B" & Split(ActiveCell.Address, "$")(2) - 1) & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range("B" & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Value = ""
Range("A" & Split(ActiveCell.Address, "$")(2) - 1).Select
Exit Sub
End If
End If
Case "Z"
If Range("Y" & Split(ActiveCell.Address, "$")(2) - 1).Value = Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Value And Range("Z" & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range("Y" & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = RGB(200, 160, 35)
Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Value & "与单元格" & Range("Y" & Split(ActiveCell.Address, "$")(2) - 1) & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range("Y" & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Value = ""
Range("Z" & Split(ActiveCell.Address, "$")(2) - 1).Select
Exit Sub
End If
End If
Case Else
If ActiveCell.Column > 26 Then Exit Sub '最大为Z列(Z的ASCII码为128),超出范围则不处理
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & Split(ActiveCell.Address, "$")(2) - 1).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & Split(ActiveCell.Address, "$")(2) - 1 & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
RCR = CStr(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1)
End If
End If
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & Split(ActiveCell.Address, "$")(2) - 1).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & Split(ActiveCell.Address, "$")(2) - 1).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & Split(ActiveCell.Address, "$")(2) - 1 & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & Split(ActiveCell.Address, "$")(2) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
RCR = CStr(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1)
End If
End If
If RCR <> "" Then Range(RCR).Select: RCR = "": Exit Sub
End Select
If Split(ActiveCell.Address, "$")(2) = 1 Then Exit Sub '活动单元格是最顶上的单元格时退出SUB
For i = 1 To (Split(ActiveCell.Address, "$")(2) - 2)
'检查同一列是否有相同的数据
If Range(Split(ActiveCell.Address, "$")(1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Split(ActiveCell.Address, "$")(1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Split(ActiveCell.Address, "$")(1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Split(ActiveCell.Address, "$")(1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Select
Exit Sub
End If
End If
'检查相邻列是否存在相同数据(相同行之前的行)
Select Case Asc(Split(ActiveCell.Address, "$")(1))
Case Asc("A") '输入A列时
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Select
Exit Sub
End If
End If
Case Asc("Z") '输入Z列时
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Select
Exit Sub
End If
End If
Case Else 'A-Z中间区段
If ActiveCell.Column > 26 Then Exit Sub '最大为Z列(Z的ASCII码为128),超出范围则不处理
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) + 1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
RCR = CStr(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1)
End If
End If
If Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Value = Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value And Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value <> "" Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Interior.Color = RGB(200, 160, 35)
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.Color = vbRed
RC = MsgBox("IMEI号:" & Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value & "与单元格" & Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i & "的IMEI号重复!是否处理?", vbYesNo + vbQuestion, "号码重复!是否处理? ------Powered By 游虫")
If RC = vbYes Then
Range(Chr(Asc(Split(ActiveCell.Address, "$")(1)) - 1) & i).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Interior.ColorIndex = False
Range(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1).Value = ""
RCR = CStr(Split(ActiveCell.Address, "$")(1) & (Split(ActiveCell.Address, "$")(2)) - 1)
End If
End If
If RCR <> "" Then Range(RCR).Select: RCR = "": Exit Sub
End Select
Next i
End Sub
相关文章推荐
- EXCEL中同一列避免重复数据[原创]
- Excel-统计不重复数据的个数,设置单元格不允许出现重复数据
- 如何避免JSP/PHP等页面数据导出EXCEL时出现科学计算法
- Excel中删除两列中重复的数据[原创]
- mysql插入大量数据时避免重复记录出现
- excel禁止(避免)输入重复数据的设置方法
- 如何避免JSP/PHP等页面数据导出EXCEL时出现科学计算法
- 如何避免MySQL出现重复数据?
- sql,key id不唯一,导致出现重复数据
- C# 读取EXCEL文件出现数据丢失问题
- oracle左连接查询出现数据重复
- Excel问题 所有数据 怎么查其中一个数据出现过几次 COUNTIF函数
- 给定的数据,然后随机生成这些数据,并且保证数据全部都生成一遍,不回出现重复生成的情况
- 通过vc 操作excel时避免重复定义的问题
- easy ui 表单提交添加遮罩,避免数据重复提交
- ListView优化机制及滑动时数据时出现的数据错乱重复问题
- OBIEE数据导出到excel图例文字出现方块乱码
- 如何在Excel的一列中查找重复的数据
- 【分析师一定要看!用数据讲故事的五个步骤】1.理解数据源;2.明确你要讲的故事;3.定义用户体验 ;4.简单法则;5.避免重复发明轮子
- SQL求一个表中非重复数据及其出现的次数