LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Set worksheet range runtime error 1004

Hi People,

I am trying to reference a range on another worrksheet in the same
woorkbook, but when I try and set the range I get a run-time error 1004
Application-defined or object-defined error. I have had this problem
in the past and you can get around this error by selecting the
worksheet before the range, but shouldn't the code I have below work?

Function GetSP(NewRec As DB_SP, Location As String, RecDate As Date) As
Integer
'Get stockpile number from SP_Info based on date range and location
number

Dim myRange As Range
Dim myCell As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Set myRange = Worksheets("SP Info").Range(Cells(2, 1),
Cells(Rows.Count, 1).End(xlUp))
For Each myCell In myRange
If (myCell.Offset(0, 1).Value = CInt(Location)) And
(myCell.Offset(0, 2).Value <= RecDate) Then
If myCell.Offset(0, 3).Value = RecDate Or myCell.Offset(0,
3).Value = Empty Then
GetSP = myCell.Value
Exit For
End If
End If
Next myCell
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Function

TIA

Dave.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro runtime 1004 error on opening worksheet Shaggyjh Excel Discussion (Misc queries) 5 May 6th 09 12:37 PM
Runtime 1004 error -- insert method of range class failed. tish Excel Discussion (Misc queries) 1 June 1st 07 04:04 PM
Runtime Error 1004 - Method Range of '_Global failed' Sworkhard Excel Programming 3 July 9th 04 04:20 AM
runtime error '1004' delete Method of Range Class Failed Tom Kennedy Excel Programming 0 April 14th 04 08:08 PM
runtime error '1004' delete Method of Range Class Failed Tom Ogilvy Excel Programming 0 April 1st 04 04:09 AM


All times are GMT +1. The time now is 10:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"