尝试使用Target.Address
和target.Address.row
,但我仍然获得无效的限定符。如果有人能提供一些帮助,我将不胜感激。
代码:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error GoTo Error1
If Target.Column = 10 Then
If Target.Address.Value = "Y" Then
Target.Address.Row.Interior.Pattern.Color = 255
End If
End If
Y
Letscontinue:
Application.EnableEvents = True
Exit Sub
Error1:
MsgBox Err.Description
Resume Letscontinue:
End Sub
答案 0 :(得分:4)
使用EntireRow
属性来对duDE的答案进行小修改....
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 10 Then
If Target.Value = "Y" Then
Target.EntireRow.Interior.Color = 255
End If
End If
End Sub
请使用内政部的Color
财产而不是PatternColor
财产
答案 1 :(得分:4)
我认为其中一个是你在尝试的?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sPass As String
'~~. This is to prevent the code from crashing when a paste happens in more
'~~> than 1 cell. Also in Pre Excel versions, replace .CountLarge with .Count
If Target.Cells.CountLarge > 1 Then Exit Sub
sPass = "PASSWORD" '<~~ Your password
Application.EnableEvents = False
On Error GoTo Error1
If Not Intersect(Target, Columns(10)) Is Nothing And _
UCase(Trim(Target.Value)) = "Y" Then
ActiveSheet.Unprotect sPass
Target.EntireRow.Interior.Color = 255
Target.EntireRow.Locked = True
ActiveSheet.Protect sPass
End If
Letscontinue:
Application.EnableEvents = True
Exit Sub
Error1:
MsgBox Err.Description
Resume Letscontinue
End Sub
答案 2 :(得分:2)
试试这个:
If Target.Column = 10 Then
If Target.Value = "Y" Then
Target.Interior.PatternColor = 255
End If
End If
答案 3 :(得分:0)
Target没有属性Target.Address.Row,但是具有Target.Row。可能是此错误原因。