[英]Method Range of object Global failed
I keep getting a method range of object __global error for my code, even though I have initialised the worksheet and ensured that the name is correct. 即使我已经初始化工作表并确保名称正确,我仍在为代码获取对象__global错误的方法范围。 Any help?
有什么帮助吗? The code is supposed to be finding a range of cells with data in to be put into a second spreadsheet
该代码应查找包含数据的单元格范围,并将其放入第二个电子表格中
Sub potential()
'Add hours for potential work to generate function
Sheets("Resourcing Sit-Rep").Select
p = Range("Potential person").End(xlDown).Row - Range("Potential person").Row
For k = 1 To p
For j = 1 To 187
If Range("hours").Offset(k, j).Value > 0 Then
Sheets("Resource Forecast").Select
Val5 = Range("Potential person").Offset(k, 1).Value
Val6 = Range("Potential person").Offset(k).Value
Val7 = Range("hours").Offset(k, j).Value
Val8 = Range("date").Offset(0, j).Value
Sheets("Resourcing Sit-Rep").Select
A = Range("Leader").Offset(0, 2).End(xlDown).Row - Range("Leader").Offset(0, 2).Row + 1
Range("Leader").Offset(A, 2).Formula = Sheets("Resource Forecast").Range("Project_Number").Value & " (" & Sheets("Resource Forecast").Range("Project_Name").Value & ") - " & Val5 & " POTENTIAL WORK"
Range("Leader").Offset(A, 3).Formula = Val6
Range("Leader").Offset(A, 4).Formula = Val7 / 7.5
Range("Leader").Offset(A, 5).Formula = Val8
Else
End If
Next j
Next k
'Range("Leader").Offset(1, 0).Resize(1, 2).AutoFill Destination:=Range("A4", Cells(Range("Leader").Offset(0, 2).End(xlDown).Row, 2)), Type:=xlFillDefault
End Sub
First thing I'd say is that you should always qualify your ranges with specifics worksheet objects. 我要说的第一件事是,您应该始终使用特定的工作表对象来限定范围。
But your issue is that this: 但是您的问题是:
Range("Potential person")
doesnt work. Range("Potential person")
无效。 The Range Method cannot find such a range. 范围方法找不到这样的范围。
Excel Named Ranges cannot have spaces in them, so either your ranges have underscores or something. Excel命名范围中不能包含空格,因此您的范围必须带有下划线或其他内容。 Try with simple test without spaces, and you should make progress.
尝试使用没有空格的简单测试,您应该会有所进步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.