Target.Address&Target.Address.Row

我试图使用Target.Addresstarget.Address.row但我保持Invlaid修饰符。 如果有人能提供一些帮助,我将不胜感激。

码:

  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 

我认为其中之一是你正在尝试的?

 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 

使用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属性

尝试这个:

  If Target.Column = 10 Then If Target.Value = "Y" Then Target.Interior.PatternColor = 255 End If End If