|
本帖最后由 lingyuncelia1 于 2016-2-19 14:25 编辑
Sub 同宫报错()
Dim arr, d, i%, j%, k%, h%, l%
Set d = CreateObject("scripting.dictionary")
For h = 1 To 7 Step 3
For l = 1 To 7 Step 3
arr = Cells(h, l).Resize(3, 3)
For i = 1 To 3
For j = 1 To 3
s = arr(i, j)
If Len(s) = 1 Then
If Not d.exists(s) Then
d(s) = Cells(h + i - 1, l + j - 1).Address
Else
MsgBox "同宫出错:" & d(s) & "---" & Cells(h + i - 1, l + j - 1).Address
End If
End If
'If Len(s) = 1 And d(s) = 2 Then MsgBox "同宫出错:"
Next
Next
d.RemoveAll
Next
Next
End Sub
有哪位大神可以详细解释黄色背景的代码?
If Not d.exists(s) Then
如果字典里面不存在s表示的关键字,则执行下面语句.
不明白为什么这样就可以求出同宫有相同的一位数(9格为一宫)
如果改成这样你能看懂不?
If d.exists(s) Then
MsgBox "同宫出错:" & d(s) & "---" & Cells(h + i - 1, l + j - 1).Address
Else
d(s) = Cells(h + i - 1, l + j - 1).Address
End If
|
|