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: 15
Default error 1004 Range object

Code that worked perfectly in Excel 97 is giving a run-time error
'1004': Application-defined or object-defined error in Excel 2003.

The error occurs on the following line in the code sample below.

Set rng = sceWB.Worksheets(ws.Name).Range(strNameAddress)


Function SearchOrderNum(OrderNum as String, DateStart as Date, DateEnd
as Date, resultsArray() As TimeUDT) As Boolean
Dim sceWB As Workbook
Dim ws As Worksheet
Dim strNameAddress as String
Dim rng As Range
Dim result As Range

Set sceWB = ThisWorkbook
For Each ws In sceWB.Worksheets
strNameAddress = ""
'set up multiple range for Find method, using named ranges with
offsets to Order No. column
For n = 1 To sceWB.Names.Count
If ws.Name = sceWB.Names(n).RefersToRange.Worksheet.Name Then
strNameAddress = strNameAddress &
sceWB.Names(n).RefersToRange.Offset(0, -4).Address & ","
End If
Next

strNameAddress = Left(strNameAddress, Len(strNameAddress) - 1)
'strip last comma

If strNameAddress < "" Then
Set rng = sceWB.Worksheets(ws.Name).Range(strNameAddress)

With rng
Set result = .Find(OrderNum, LookIn:=xlValues)


The inner For loop sets up a string of columns to use in the Find
method.

For the first worksheet, strNameAddress is a string of 261 characters,
ie "$A:$A,$G:$G,$M:$M,$S:$S,$Y:$Y,$AE:$AE ......$GQ:$GQ".

I don't know if the error is caused by the length of the string, but
does anyone know how to solve this problem? Is there any reason why
it should work in Excel 97 but not 2003? Also I am open to
suggestions about any other ways to set up a Range object of multiple
columns to use in the Find method.

Thanks
Tony

 
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
runtime error 1004 method range of object '_global failed valdesd Excel Discussion (Misc queries) 2 October 6th 05 07:26 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Runime Error 1004 Method Range of Object Global Failed Mohan[_5_] Excel Programming 3 May 21st 04 03:35 PM
"Run-time error '1004'" Method 'Range' of object '_global' failed. haisat[_2_] Excel Programming 0 October 20th 03 12:13 PM


All times are GMT +1. The time now is 03:05 AM.

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"