返回列表 上一主題 發帖

[發問] 一邊輸入一邊即時比對

用錯事件了。
  1. Private Sub Worksheet_Change(ByVal Target As Excel.Range)
  2.     If Target.Column <> 5 Then Exit Sub
  3.     If Target.Count > 1 Then Exit Sub
  4.     If Sheets("DATA").[b:b].Find(Target, , , 1) Is Nothing Then
  5.         Application.EnableEvents = False
  6.         Target.Offset(, -3) = "?"
  7.         Target.Offset(, -3).Font.ColorIndex = 3
  8.         Application.EnableEvents = True
  9.     End If
  10. End Sub
複製代碼

TOP

Worksheet_SelectionChange是在點擊儲存格就發生的事件
不適合你在寫入儲存格才要判斷執行任務
所以要 寫在Worksheet_Change事件中。
改過後要清除寫入的問號:
Target.Offset(, -3) = "?"
Target.Offset(, -3).Font.ColorIndex = 3
ELSE
Target.Offset(, -3) = ""
Target.Offset(, -3).Font.ColorIndex = 0
  
      Application.EnableEvents = True
    End If
加上紅字部份

TOP

我運行是ok的。你要不要把無法運行的檔案附上來?

TOP

        靜思自在 : 口說一句好話,如口出蓮花;口說一句壞話如口吐毒蛇。
返回列表 上一主題