返回列表 上一主題 發帖

[發問] 如何判斷找出資料並標示不同顏色

回復 1# luke

沒附檔案?

工作表模組
  1. Private Sub worksheet_change(ByVal target As Range)
  2. If target.Column <= 2 Then
  3.    LR = Sheet2.[A1].End(xlDown).Row
  4.    Set Rng = Sheet2.Range(Sheet2.Cells(1, target.Column * 2 - 1), Sheet2.Cells(LR, target.Column * 2))
  5.    Set X = Rng.Find(target, , , xlWhole)
  6.    If X Is Nothing Then
  7.       target.Interior.ColorIndex = 3
  8.    Else
  9.       target.Interior.ColorIndex = X.Interior.ColorIndex
  10.    End If
  11. End If
  12. End Sub
複製代碼

TOP

回復 3# luke

儲存格須逐格輸入

工作表sheet1模組
  1. Private Sub worksheet_change(ByVal target As Range)
  2. If target.Column <= 2 Then
  3.    LR = Sheet2.[A1].End(xlDown).Row
  4.    Set Rng = Sheet2.Range(Sheet2.Cells(1, target.Column * 2 - 1), Sheet2.Cells(LR, target.Column * 2))
  5.    Set X = Rng.Find(target, , , xlWhole)
  6.    If X Is Nothing Then
  7.       target.Font.ColorIndex = 3
  8.    Else
  9.       target.Interior.ColorIndex = X.Interior.ColorIndex
  10.    End If
  11. End If
  12. End Sub
複製代碼

TOP

回復 3# luke

儲存格已先全部輸入好,一次判斷全部儲存格

一般模組
  1. Sub xx()
  2. For Each target In [A1].CurrentRegion
  3. If target.Column <= 2 Then
  4.    LR = Sheet2.[A1].End(xlDown).Row
  5.    Set Rng = Sheet2.Range(Sheet2.Cells(1, target.Column * 2 - 1), Sheet2.Cells(LR, target.Column * 2))
  6.    Set X = Rng.Find(target, , , xlWhole)
  7.    If X Is Nothing Then
  8.       target.Font.ColorIndex = 3
  9.    Else
  10.       target.Interior.ColorIndex = X.Interior.ColorIndex
  11.    End If
  12. End If
  13. Next
  14. End Sub
複製代碼

TOP

        靜思自在 : 甘願做、歡喜受。
返回列表 上一主題