|
Sub celia()
Dim rng As Range, mycount As Integer, a As Integer
For i = 1 To 9
If Cells(i, 1).Value Like "*5*" Then
mycount = mycount + 1
If mycount = 1 Then Cells(i, 1).Font.Size = 36
End If
Next i
End Sub
运行以上代码,可得右图:
9个格只有A3含有数字5.数字5在A1到A9中只出现一次。如果我想将代码改写,从A1到A9,数字1到9,在9个数字中只出现一次的数字,其所在单元格以36字体标明。代码应如何更改啊?
- Sub Macro1()
- Dim arr, d, i%, j%, k%, h%, l%
- Set d = CreateObject("scripting.dictionary")
- [a1:i9].Font.Size = 12
- 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) = 2 Then
- If Not d.exists(s) Then
- d(s) = Cells(h + i - 1, l + j - 1).Address
- Else
- d(s) = d(s) & "," & Cells(h + i - 1, l + j - 1).Address
- End If
- End If
- Next
- Next
- b = d.items
- For k = 0 To d.Count - 1
- If InStr(b(k), ",") Then Range(b(k)).Font.Size = 36
- Next
- d.RemoveAll
- Next
- Next
- End Sub
复制代码
|
|