- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2011-12-16 17:52
| 只看該作者
本帖最後由 GBKEE 於 2011-12-16 17:53 編輯
回復 1# 小俠客 - Option Explicit
- Public Rng As Range, Rng1 As Range, Rng2 As Range
- Sub Restart()
- Sheets(1).Cells.Clear
- End Sub
- Sub Draw()
- Dim B As Integer, C As Integer, d As Integer
- With Sheet1
- L:
- B = Int(100 * Rnd() + 1)
- C = Application.CountIf(.Range("A:A"), B) '比對是否重復
- If C = 1 Then GoTo L: '重做亂數
- d = Application.CountA(.Range("A:A")) + 5
- .Cells(d, 1) = B
- .Cells(d, 1).Select
- Bingo (B)
- End With
- End Sub
- Sub Paper()
- Dim E As Range, B As Integer, i As Integer, ii As Integer
- Set Rng = [Sheet1!I1:M5] '設定數字區域
- For Each E In Rng
- L:
- B = Int(100 * Rnd() + 1)
- C = Application.CountIf(Rng, B) '比對是否重復
- If C = 1 Then GoTo L:
- E = B
- Next
- For i = 1 To 5 '設定對角線由左至右區域
- If i = 1 Then
- Set Rng1 = Rng.Cells(i, i)
- Else
- Set Rng1 = Union(Rng1, Rng.Cells(i, i))
- End If
- Next
- ii = 5
- For i = 1 To 5 '設定對角線由右至左區域
- If i = 1 Then
- Set Rng2 = Rng.Cells(i, ii)
- Else
- Set Rng2 = Union(Rng1, Rng.Cells(i, ii))
- End If
- ii = ii - 1
- Next
- End Sub
- Sub Bingo(No As Integer)
- Dim f As Range, d As Integer, C As Range, i As Integer, ii As Integer
- Set f = Rng.Find(No, LookIn:=xlValues, LOOKAT:=xlWhole) '尋找數字
- If f Is Nothing Then Exit Sub
- If Not f Is Nothing Then
- f.Font.ColorIndex = 3 '找到數字給字體顏色
- f.Font.FontStyle = "粗體" '找到數字給字型樣式
- End If
- For i = 1 To Rng.Columns.Count
- d = 0
- For Each C In Rng.Columns(i).Cells
- If C.Font.ColorIndex = 3 Then d = d + 1
- Next
- If d = 5 Then Rng.Columns(i).Select: GoTo ok
- Next
- For i = 1 To Rng.Rows.Count '檢查橫列
- d = 0
- For Each C In Rng.Rows(i).Cells
- If C.Font.ColorIndex = 3 Then d = d + 1
- Next
- If d = 5 Then Rng.Rows(i).Select: GoTo ok
- Next
- d = 0
- For Each C In Rng1 '檢查對角線
- If C.Font.ColorIndex = 3 Then d = d + 1
- Next
- If d = 5 Then Rng1.Select: GoTo ok
- d = 0
- For Each C In Rng2 '檢查對角線
- If C.Font.ColorIndex = 3 Then d = d + 1
- Next
- If d = 5 Then Rng2.Select: GoTo ok
- Exit Sub
- ok:
- MsgBox "Bingo"
- End Sub
複製代碼 |
|