返回列表 上一主題 發帖

[發問] 格式化規則 VBA

[發問] 格式化規則 VBA

大大們好

我想要問說可以針對C欄的資料 對A欄中有的標記上黃色嗎(附件一)

試著弄了一下 會變成 (附件二) 這要怎麼修改?? 麻煩了 感謝
Dim i As String
For j = 1 To 5
    Worksheets(1).Columns("A:A").Select
    i = Worksheets(1).Range("C" & j)
    Selection.FormatConditions.Add Type:=xlTextString, String:=i, _
        TextOperator:=xlContains
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
    End With
Next

Q55.png (4.93 KB)

附件一

Q55.png

Q59871.png (3.89 KB)

附件二

Q59871.png

本帖最後由 PKKO 於 2014-11-23 13:08 編輯

回復 1# s13983037
    此巨集假設你是在sheets(1)下面操作,如果不是就在range前面加上    sheets(1).
試試看
  1. Sub test()
  2.     For i = 1 To Range("A65536").End(xlUp).Row
  3.         With Cells(i, 1)
  4.             For j = 1 To Range("C65536").End(xlUp).Row
  5.                 If .Value = Cells(j, 3) Then
  6.                     .Interior.ColorIndex = 6 '是的話黃色
  7.                     Exit For '是就離開比對
  8.                 Else
  9.                     .Interior.ColorIndex = 2 '不是的話白色
  10.                 End If
  11.             Next
  12.         End With
  13.     Next
  14. End Sub
複製代碼
interior        font         HTML        bgcolor=         Red<        Green         Blue        Color
Black        [Color 1]         #000000        #000000         0        0        0         [Black]
White        [Color 2]         #FFFFFF        #FFFFFF         255        255        255         [White]
Red         [Color 3]         #FF0000        #FF0000         255        0        0         [Red]
Green         [Color 4]         #00FF00        #00FF00         0        255        0         [Green]
Blue         [Color 5]         #0000FF        #0000FF         0        0        255         [Blue]
Yellow         [Color 6]         #FFFF00        #FFFF00         255        255        0         [Yellow]
Magenta         [Color 7]         #FF00FF        #FF00FF         255        0        255         [Magenta]
Cyan         [Color 8]         #00FFFF        #00FFFF         0        255        255         [Cyan]
PKKO

TOP

回復 2# PKKO


    謝謝大大..剛剛試用過了 OK!!

TOP

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