|
楼主 |
发表于 2018-1-8 15:11
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
嗯,测试了一下,当原始数据中含有负数时,确实有问题。
Sheet1中的触发代码修改如下:
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Count > 1 Then Exit Sub
- If Target.Column <> 8 Then Exit Sub
- If Target = "" Then Exit Sub
-
- m = Range("A1").End(xlDown).Row
- Range("A1").Resize(m).Interior.ColorIndex = 0
- If Target.Row = 1 Then Exit Sub
-
- sj = Range("A1").Resize(m)
- s = Target.Text
- i1 = 1
- For i = 2 To Len(s)
- t = Mid(s, i, 1)
- If Not IsNumeric(t) Then '="+" or "-"
- t = Val(Mid(s, i1, i - i1 + 1))
- For i2 = 2 To m
- If sj(i2, 1) = t Then sj(i2, 1) = "": Exit For
- Next
- i1 = i
- End If
- Next
-
- For i = 2 To m
- If sj(i, 1) = "" Then Cells(i, 1).Interior.ColorIndex = 6
- Next
-
- End Sub
复制代码 |
|