我正在尝试使用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发布于 2014-09-09 15:48:44
我想这其中的一个就是你正在尝试的?
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发布于 2014-09-09 15:39:45
通过使用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属性
发布于 2019-09-27 14:54:49
目标没有属性Target.Address.Row,但具有Target.Row。这可能是这个错误的原因。
https://stackoverflow.com/questions/25738686
复制相似问题