相交错误:对象‘_Global’的方法‘Range’失败

相交错误:对象‘_Global’的方法‘Range’失败

为什么当我输入以下内容时,会出现此错误:对象“_Global”的方法“Range”失败:

Private Sub Workbook_SheetChange(ByVal WS As Object, ByVal Target As Range)
Dim NTT As Range
Set WS = ActiveSheet
Set NTT = WS.Range("$A$1:$U$154")

If Not Intersect(Target, Range("NTT")) Is Nothing Then     '< error Here

但当我放的时候

Private Sub Workbook_SheetChange(ByVal WS As Object, ByVal Target As Range)
Dim NTT As Range
Set WS = ActiveSheet

If Not Intersect(Target, Range("A$1:$U$154")) Is Nothing Then

不幸的是,在代码中我需要使用这种格式:Range(“Name”)

答案1

您需要使用Range 对象而不是细绳

Dim WS As Worksheet, NTT As Range
Set WS = ActiveSheet
Set NTT = WS.Range("$A$1:$U$154")
If Not Intersect(Target, NTT) Is Nothing Then............

你非常接近了!

相关内容