vba 目标地址和目标地址行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/25738686/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Target.Address & Target.Address.Row
提问by user1624926
I'm trying to use Target.Addressand target.Address.rowhowever I keep get Invlaid qualifier.  I would be grateful if anyone can offer some help please.
我正在尝试使用Target.Address,target.Address.row但是我一直在获得 Invlaid 限定符。如果有人可以提供一些帮助,我将不胜感激。
Code:
代码:
    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
采纳答案by Siddharth Rout
I think one of these is what you are trying?
我认为其中之一是您正在尝试的?
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
回答by whytheq
Small amendment to duDE's answer by using the EntireRowproperty ....
通过使用该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
Please use the Interior's Colorproperty rather than PatternColorproperty
请使用内部的Color财产而不是PatternColor财产
回答by Sharunas Bielskis
Target has not property Target.Address.Row, but has Target.Row. It can be this error reason.
Target 没有属性 Target.Address.Row,但有 Target.Row。可能是这个错误原因。

