![](/img/trans.png)
[英]Run-time error '1004' : Method 'Range' of object'_Global' failed
[英]VBA Run-time error '1004': Method 'Range' of object '_Global' Failed
我正在嘗試從一個工作簿中獲取一個單元格值,並查找它是否出現在另一工作簿的列中,並返回“是”或“否”的答案。 我認為最好的方法是“相交”命令。 我收到對象“全局”失敗的“方法”范圍”錯誤。
任何的建議都受歡迎。
' 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.