|
本帖最后由 lingyuncelia1 于 2016-3-2 14:52 编辑
为什么运行以下代码会弹出警告框:缺少函数或变量?l老显示“c”有问题,不明白“c”有什么问题。
Sub 四链法()
'同行四链法
For i = 1 To 9
For k = 1234 To 6789
a = Left(k, 1)
b = Mid(k, 2, 1)
c = Mid(k, 3, 1)
d = Right(k, 1)
If Val(d) > Val(c) > Val(b) > Val(a) Then
For j = 1 To 9
s = CStr(Cells(i, j))
If s = a & b Or s = a & c Or s = a & d Or s = b & c Or s = b & d Or s = c & d _
& s = a & b & c Or s = a & b & d Or s = a & c & d Or s = b & c & d _
& s = a & b & c & d Then
n = n + 1
x = x & "," & Cells(i, j).Address
End If
Next
End If
If n = 4 Then
Range(Mid(x, 2)).Font.Size = 36
For Each Rng In Cells(i, 1).Resize(1, 9)
If Rng.Font.Size = 11 Then
Rng.Value = Replace(Rng.Text, a, "")
Rng.Value = Replace(Rng.Text, b, "")
Rng.Value = Replace(Rng.Text, c, "")
Rng.Value = Replace(Rng.Text, d, "")
End If
Next
End If
n = 0: x = ""
Next
Next
End Sub
看看这样行不行(未经测试) - Sub 四链法()
- '同行四链法
- For i = 1 To 9
- For k = 1234 To 6789
- a = Left(k, 1)
- b = Mid(k, 2, 1)
- c = Mid(k, 3, 1)
- d = Right(k, 1)
- If d > c And c > b And b > a Then
- For j = 1 To 9
- s = CStr(Cells(i, j))
- If s = a & b Or s = a & c Or s = a & d Or s = b & c Or s = b & d Or s = c & d _
- Or s = a & b & c Or s = a & b & d Or s = a & c & d Or s = b & c & d _
- Or s = a & b & c & d Then
- n = n + 1
- x = x & "," & Cells(i, j).Address
- Else
- y = y & "," & Cells(i, j).Address
- End If
- Next
- End If
- If n = 4 Then
- Range(Mid(x, 2)).Font.Size = 36
- yy = Mid(y, 2)
- Range(yy).Replace a, ""
- Range(yy).Replace b, ""
- Range(yy).Replace c, ""
- Range(yy).Replace d, ""
- End If
- n = 0: x = "": y = ""
- Next
- Next
- End Sub
复制代码
|
|