返回列表 上一主題 發帖

[發問] 請大師們幫忙自動變換顏色,謝謝

http://blog.xuite.net/hcm19522/twblog/205029860

TOP

經過准大再三指導, 終於完成了, 謝謝准大.
test.gif

TOP

TOP

回復 23# yen956
Sorry, 回應錯主題, 對 s7659109大大及相關讀者均非常抱歉,
已重新貼到下列主題中, 抱歉!!
http://forum.twbts.com/viewthrea ... a=pageD1&page=3

TOP

經准大再三指正, 終於完成
test.gif
顯示輸入值填滿顏色2.rar (28.32 KB)

TOP

連續兩次都貼錯地方, 實在不可原諒!!
想貼的是這個!!
試試看!!
sheet1(設備列表)的VBA Code如下:
  1. Option Explicit
  2. Private Sub Worksheet_Change(ByVal Target As Range)
  3.     Dim rngA As Range, rngB As Range, foundCel As Range
  4.     Dim lastRow As Long
  5.     If Target.Count > 1 Then Exit Sub         '如果一次Change太多格就離開
  6.     lastRow = Sheets("公司清單").Cells(Rows.Count, 2).End(xlUp).Row
  7.     Set rngA = Sheets("公司清單").Range("B2:B" & lastRow & "")   '設定 "公司清單" 的範圍給 rngA
  8.     lastRow = Cells(Rows.Count, 2).End(xlUp).Row
  9.     Set rngB = Range("B2:B" & lastRow & "")          '設定 "設備列表" 的範圍給 rngB
  10.     If Not Intersect(Target, rngB) Is Nothing Then
  11.         Set foundCel = rngA.Find(Target, lookat:=xlWhole)       'rngA 中尋找 Target
  12.         If Not foundCel Is Nothing Then        '有找到
  13.             Target.Offset(0, -1).Resize(1, 11).Interior.ColorIndex = _
  14.                         foundCel.Offset(0, 1).Interior.ColorIndex
  15. '        Else
  16.             '建議 "設備列表" 的 "使用公司" 用 驗證清單 輸入
  17.             '則此處就不必檢查輸入是否有錯誤, 換言之, 就沒有 Else 這一段
  18.             '又 驗證清單 字體很小又不能改, 不適合弱視者,
  19.             '建議 "設備列表" 整頁全部改用小字體, 再放大檢視比例
  20.         End If
  21.     End If
  22. End Sub
複製代碼
sheet2(公司清單)的VBA Code如下:
  1. Option Explicit
  2. Public colorNum As Integer

  3. '先執行此VBA一次, 以建立代碼表
  4. Sub 顏色代碼表()
  5.     Dim i As Integer
  6.     For i = 1 To 28
  7.         Cells(i, 15).Interior.ColorIndex = i
  8.         Cells(i, 16).Interior.ColorIndex = i + 28
  9.     Next
  10. End Sub

  11. '作用:用以編輯"公司清單"C欄的儲存格顏色
  12. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  13.     Dim rng As Range
  14.     If Target.Count > 1 Then Exit Sub
  15.     Set rng = Application.Union([C:C], [O1:P28])
  16.     If Intersect(Target, rng) Is Nothing Then Exit Sub
  17.     If Target.Column = 3 Then
  18.         Target.Interior.ColorIndex = colorNum
  19.     Else
  20.         colorNum = Target.Interior.ColorIndex
  21.     End If
  22. End Sub
複製代碼
test2.gif
測試檔案.rar (381.48 KB)

TOP

        靜思自在 : 口說好話、心想好意、身行好事。
返回列表 上一主題