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. 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. The Range Method cannot find such a range.
Excel Named Ranges cannot have spaces in them, so either your ranges have underscores or something. Try with simple test without spaces, and you should make progress.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.