简体   繁体   English

VBA运行时错误'1004':对象'_Global'的方法'Range'失败

[英]VBA Run-time error '1004': Method 'Range' of object '_Global' Failed

I'm trying to take a cell value from one workbook, and find if it occurs in a column on another workbook, returning a "yes" or "no" answer. 我正在尝试从一个工作簿中获取一个单元格值,并查找它是否出现在另一工作簿的列中,并返回“是”或“否”的答案。 I thought the best way to do this would be the Intersect command. 我认为最好的方法是“相交”命令。 I'm getting the "method 'range' of object 'global' failed" error. 我收到对象“全局”失败的“方法”范围”错误。

Any advice would be welcome. 任何的建议都受欢迎。

' Next part puts a "Yes" or "No" in PHO column
' based on one-at-a-time comparison of new keys in column Y
' against Column C of today's PHO report
Dim RowCount As Long
Dim CurrentPHO As Workbook
Dim TodaysDate As String
Dim PHOCompare As Range
Dim CurrentRow As String
Dim CellCounter As Range

TodaysDate = Format(Date, "m-d-yyyy")

Set CurrentPHO = Workbooks.Open("\\netapp02\ProcurementDocs$\PHO\PHO " & TodaysDate & ".xlsx") 'This Opens and defines today's PHO report
Set PHOCompare = CurrentPHO.Worksheets("Detail").Range("C:C")


For RowCount = 2 To LastRow
    Set CellCounter = Workbooks("IBUT 11-4-14.xlsx").Sheets("Sheet1").Range("Y" & RowCount)
    If Not Intersect(CellCounter, Range(PHOCompare)) Is Nothing Then
        Range("K" & RowCount).Value = "No"
            Else: Range("K" & RowCount).Value = "Yes"
    End If
Next RowCount
Dim RowCount As Long
Dim CurrentPHO As Workbook
Dim TodaysDate As String
Dim PHOCompare As Range
Dim CurrentRow As String
Dim CellCounter As Range
Dim FoundCell As Range

TodaysDate = Format(Date, "m-d-yyyy")

Set CurrentPHO = Workbooks.Open("\\netapp02\ProcurementDocs$\PHO\PHO " & TodaysDate & ".xlsx") 'This Opens and defines today's PHO report
Set PHOCompare = CurrentPHO.Worksheets("Detail").Range("C:C")


For RowCount = 2 To LastRow
    Set CellCounter = Workbooks("IBUT 11-4-14.xlsx").Sheets("Sheet1").Range("Y" & RowCount)

Set FoundCell = PHOCompare.Find(CellCounter.Value)
    Range("K" & RowCount).Value = IIf(IsEmpty(FoundCell), "No", "Yes")
Set FoundCell = Nothing

Next RowCount

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行时错误'1004':对象'_Global'的方法'Range'失败 - Run-time error '1004' : Method 'Range' of object'_Global' failed 运行时错误'1004':对象'_Global'的方法'Range'失败 - Run-time error '1004': Method 'Range' of object '_Global' failed 运行时错误'1004'对象'_Global'的方法'Range'失败 - Run-time error '1004' Method 'Range' of object'_Global' failed 运行时错误'1004':对象'_Global'的方法'Range'失败6 - Run-time error '1004' : Method 'Range' of object'_Global' failed 6 运行时错误'1004' - 对象'_Global'的方法'范围'失败 - Run-time error '1004' - Method 'Range' of object'_Global' failed 运行时错误“1004”-object“_Global”的方法“范围”失败 - Run-time error '1004' - Method 'Range' of object '_Global' failed 运行时错误1004-对象'_Global'的方法'Range'失败 - Run-time error 1004 - Method 'Range' of object'_Global' failed 运行时错误'1004'-VBA中对象'_Global'的方法'Range'失败 - Run-time error '1004' - Method 'Range' of object'_Global' failed in VBA Excel VBA 运行时错误'1004'对象'_Global'的方法'范围'失败 - Excel VBA Run-Time Error '1004' Method 'Range' of object'_Global' Failed VBA-运行时错误'1004'-对象'_Global'的方法'Range'失败 - VBA - Run-time error '1004' - Method 'Range' of object'_Global' failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM