- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 3# linsurvey2005 - Dim D As Object, xColor As Integer '模組內的私用變數(模組內的程式可用這變數)
- Private Sub UserForm_Initialize() '表單初始化(未顯示時)的預設事件
- Set D = CreateObject("Scripting.Dictionary") '字典物件
- With ActiveSheet
- For Each A In .UsedRange
- If A <> "" Then
- If D.EXISTS(A.Value) Then '字典物件(A.Value) 存在 條件成立
- Set D(Trim(A)) = Union(D(Trim(A)), A)
- 'Union 方法 傳回兩個或多個範圍的合併範圍
- Else
- Set D(Trim(A)) = A '設立字典物件(A.Value)為儲存格
- End If
- End If
- Next
- Label1.Caption = .Name '工作表的名稱
- .Cells.Interior.ColorIndex = xlNone '刪除顏色: 顏色=無
- End With
- ComboBox1.List = D.keys
- UserForm_Click '可以有顏色的選擇嗎?
- End Sub
- Private Sub ComboBox1_Change()
- With ActiveSheet
- '.Cells 儲存格物件的集合
- .Cells.Interior.ColorIndex = xlNone '刪除顏色: 顏色=無
- If ComboBox1.ListIndex > -1 Then '-1 不在ComboBox1的List中
- D(ComboBox1.Value).Interior.ColorIndex = xColor '儲存格填滿
- MsgBox ComboBox1 & "總數=" & D(ComboBox1.Value).Cells.Count & vbLf & "儲存格位置在 " & D(ComboBox1.Value).Address
- End If
- End With
- End Sub
- Private Sub UserForm_Click() '在表單上按下滑鼠的事件
- Do
- xColor = Application.InputBox("請選擇輸入顏色號碼: 1-56 !! ", Type:=1)
- Loop Until xColor >= 1 And xColor <= 56
-
- End Sub
複製代碼 |
|