|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
yzyyyyyyy 发表于 2012-9-20 15:08
感谢上面两位大侠的出手相助
短信收到,请测试- Function chk(ByVal sfzhm As String) As String
- Dim temp$, jyw
- temp = sfzhm
- If Len(temp) = 18 Then
- Dim i, ii, w, s, cs As Integer
- w = 1
- s = 0
- For i = 1 To 17
- ii = 18 - i
- w = (w * 2) Mod 11
- cs = Asc(Mid$(temp, 18 - i, 1)) - 48
- If cs >= 0 And cs < 10 Then
- s = s + cs * w
- Else
- chk = "第" & ii & "位,不是数字!"
- i = 20
- End If
- Next
- If i = 18 Then
- s = (12 - s Mod 11) Mod 11
- jyw = LTrim$(str(s))
- If s = 10 Then
- jyw = "X"
- If Mid(sfzhm, 18, 1) = "X" Then chk = "正确!" Else chk = "错!末位应是:X"
- Else
- If Mid(sfzhm, 18, 1) = jyw Then chk = "正确!" Else chk = "错!末位应是:" & jyw
- End If
- End If
- Else
- chk = "位数不对!"
- End If
- End Function
- Sub test()
- Dim ar, br, cr, i&, j&, x&, rng As Range, str$
- ar = Sheet4.Range("a1").CurrentRegion
- ReDim br(1 To UBound(ar), 1 To 7)
- ReDim cr(1 To UBound(ar), 1 To 1)
- Sheet4.UsedRange.Offset(1).Font.ColorIndex = -4105
- For i = 2 To UBound(ar)
- str = chk(ar(i, 24))
- If str <> "正确!" Then
- x = x + 1
- cr(i - 1, 1) = str
- For j = 1 To 5
- br(x, j) = ar(i, j)
- Next
- br(x, 6) = ar(i, 24)
- br(x, 7) = str
- If rng Is Nothing Then Set rng = Sheet4.Range("x" & i) Else Set rng = Union(rng, Sheet4.Range("x" & i))
- End If
- Next
- If Not rng Is Nothing Then rng.Font.ColorIndex = 3
- Sheet1.UsedRange.Offset(1).ClearContents
- Sheet1.Range("f:f").NumberFormatLocal = "@"
- Sheet1.Range("a2").Resize(x, 7) = br
- Sheet4.Range("z2").Resize(UBound(cr)) = cr
- End Sub
复制代码 |
|