|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
优化后的代码:- Option Explicit
- Public Sub huanghou()
- Dim x(1 To 8, 1 To 8), y(1 To 8, 1 To 8), i%, j%, m%, t!, n&
- Dim k1%, k2%, k3%, k4%, k5%, k6%, k7%, k8%
- Dim xx(1 To 8), yy(1 To 8), i1%, j1%, jg$, jgs%, szjg
- ReDim szjg(1 To 1000, 1 To 2)
- t = Timer
- jgs = 0: n = 0
- For i = 1 To 8
- For j = 1 To 8
- x(i, j) = i: y(i, j) = j
- Next j, i
- Range("j2:k" & Rows.Count).ClearContents
- For k1 = 1 To 8
- xx(1) = x(1, k1): yy(1) = y(1, k1)
- For k2 = 1 To 8
- If k2 = k1 Then GoTo 100
- xx(2) = x(2, k2): yy(2) = y(2, k2)
- For k3 = 1 To 8
- If k3 = k2 Or k3 = k1 Then GoTo 100
- xx(3) = x(3, k3): yy(3) = y(3, k3)
- For k4 = 1 To 8
- If k4 = k3 Or k4 = k2 Or k4 = k1 Then GoTo 100
- xx(4) = x(4, k4): yy(4) = y(4, k4)
- For k5 = 1 To 8
- If k5 = k4 Or k5 = k3 Or k5 = k2 Or k5 = k1 Then GoTo 100
- xx(5) = x(5, k5): yy(5) = y(5, k5)
- For k6 = 1 To 8
- If k6 = k5 Or k6 = k4 Or k6 = k3 Or k6 = k2 Or k6 = k1 Then GoTo 100
- xx(6) = x(6, k6): yy(6) = y(6, k6)
- For k7 = 1 To 8
- If k7 = k6 Or k7 = k5 Or k7 = k4 Or k7 = k3 Or k7 = k2 Or k7 = k1 Then GoTo 100
- xx(7) = x(7, k7): yy(7) = y(7, k7)
- For k8 = 1 To 8
- If k8 = k7 Or k8 = k6 Or k8 = k5 Or k8 = k4 Or k8 = k3 Or k8 = k2 Or k8 = k1 Then GoTo 100
- xx(8) = x(8, k8): yy(8) = y(8, k8)
- m = 0: jg = "": n = n + 1
- For i1 = 1 To 7
- For j1 = i1 + 1 To 8
- If Abs(xx(i1) - xx(j1)) = Abs(yy(i1) - yy(j1)) Then
- GoTo 100
- Else
- m = m + 1
- End If
- Next j1, i1
- If m = 28 Then
- 'Range(Cells(1, 1), Cells(8, 8)).ClearContents
- For i = 1 To 8
- jg = jg & xx(i) & yy(i) & ","
- 'Cells(xx(i), yy(i)).Value = "●"
- Next i
- jg = Left(jg, Len(jg) - 1)
- jgs = jgs + 1
- szjg(jgs, 1) = jgs: szjg(jgs, 2) = jg
- 'Cells(Rows.Count, 10).End(xlUp).Offset(1) = jgs
- 'Cells(Rows.Count, 11).End(xlUp).Offset(1) = jg
- 'MsgBox "这是第" & jgs & "种结果", , "友情提示"
- End If
- 100:
- Next k8, k7, k6, k5, k4, k3, k2, k1
- Range("j2").Resize(UBound(szjg), 2) = szjg
- MsgBox "共用时" & Format(Timer - t, "0.0000") & "秒,共比较" & n & "次,筛选出" & jgs & "种结果", , "友情提示"
- End Sub
复制代码 |
|