- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 3# s13983037
要說清楚,只要A欄每一儲存格的字串開頭在F欄中有出現就變色
ThisWorkbook物件模組的程式碼- Option Explicit
- Private Sub Workbook_Open()
- Run "SHEET1.Auto_Open", Range("A:A")
- 'SHEET1: Worksheet(1)->VBA的物件名稱
- '你可修改
- End Sub
複製代碼 SHEET1物件模組的程式碼- Option Explicit
- Dim Rng As Range, Ar
- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim R
- If Rng Is Nothing Then Set_Rng
- If Intersect(Target, Rng) Is Nothing Then
- Auto_Open [a:a]
- ElseIf Not Intersect(Target, Rng) Is Nothing Then
- If Ar(Target.Row, 1) <> Target Then
- With Range("a:a").SpecialCells(xlCellTypeConstants)
- For Each R In .SpecialCells(xlCellTypeConstants)
- If UCase(R) Like UCase(Target & "*") Then
- R.Interior.ColorIndex = 6
- Else
- R.Interior.ColorIndex = xlNo
- End If
- Next
- End With
- End If
- Ar = Rng.Value
- End If
- End Sub
- Private Sub Set_Rng()
- Set Rng = Range("F1")
- Set Rng = Range(Rng, Rng.End(xlDown))
- Ar = Rng.Value
- End Sub
- Private Sub Auto_Open(Sheet_Rng As Range)
- Dim E As Range, R As Range
- Set_Rng
- With Sheet_Rng
- .Interior.ColorIndex = xlNo
- If Application.CountA(.Cells) > 0 Then
- For Each E In Rng
- For Each R In .SpecialCells(xlCellTypeConstants)
- If UCase(R) Like UCase(E) & "*" Then
- R.Interior.ColorIndex = 6
- End If
- Next
- Next
- End If
- End With
- End Sub
複製代碼 |
|