返回列表 上一主題 發帖

[發問] 如何才能找尋所要的資料並在儲存格塗色?

剛剛把 chin15 大大所發的程式碼加以延伸的話 應該能達到樓主的需求





附檔內 為 A 欄位 和 B欄位的對比, 如果B欄位內有A欄位的話,即會在C欄位相對儲存格打勾
但是有個缺點.. 如果資料是數字狀態 那就會出現錯亂..
如  10 20 30  和 100 110 120 130   會誤判...


對比改良版.rar (26.16 KB)

TOP

本帖最後由 chin15 於 2011-4-28 08:41 編輯

看起來應該是在a欄比對d1儲存格
  1. Sub module1()
  2.     Dim x$, c As Range, data As Range
  3.     x = [d1]
  4.     For Each c In Range([a1], [a65536].End(3))
  5.         If c = x Then
  6.             If data Is Nothing Then
  7.                 Set data = c
  8.             Else
  9.                 Set data = Union(data, c)
  10.             End If
  11.         End If
  12.     Next
  13.     If Not data Is Nothing Then
  14.     With data
  15.         .Interior.ColorIndex = 3
  16.         .Offset(, 1) = "V"
  17.     End With
  18.     End If
  19. End Sub
複製代碼

TOP

本帖最後由 mark15jill 於 2011-4-28 08:32 編輯

oobird大大 所發的程式碼就是樓主要的效果了...
而且程式精簡很多
如果要尋找其他關鍵字 把 john改掉即可..

TOP

回復 3# oobird


謝謝你
但是我只要A欄位有出現john時
在B欄那邊才會打勾
那我應該要怎麼做呢?

TOP

本帖最後由 oobird 於 2011-4-27 15:01 編輯

加上右側打勾
  1. Sub yy()
  2. With Application.ReplaceFormat.Interior
  3.         .ColorIndex = 3
  4.     End With
  5.    Cells.Replace What:="john", Replacement:="=1/0", ReplaceFormat:=True
  6.    With Cells.SpecialCells(xlCellTypeFormulas, 16)
  7.    .Value = "john"
  8.    .Offset(, 1) = "√"
  9.    End With
  10. End Sub
複製代碼

TOP

用個新手的方法..
'如果 有出現john 則 該儲存格背景色為 紅色  <--說明
    With Application.ReplaceFormat.Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Cells.Replace What:="john", Replacement:="john", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=True

TOP

        靜思自在 : 脾氣嘴巴不好,心地再好也不能算是好人。
返回列表 上一主題