PC Review


Reply
Thread Tools Rate Thread

Data Error 9 Subprocedure Out of Range

 
 
Steve
Guest
Posts: n/a
 
      5th Dec 2008
Sub Find_Todays_Date()
Dim FindString As Date
Dim Rng As Range
FindString = CLng(Date)
With Sheets("Sheet1").Range("A:A")
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
MsgBox "Nothing found"
End If
End With
End Sub


This is my code. It is supposed to goto the date when executed. It works
fine on my machine, but I tried putting it on someone else's and it gave me a
data error message. It said something like the subprocedure is out of range.
It was Data Error 9. I've checked the refrence style setting in the options
pannel and they are the same on both machines. We are both using MS 2003, but
come to think of it Im not sure which SP the other one is using... Any ideas?
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      5th Dec 2008
An error 9 (Subscript Out Of Range) error occurs when you attempt to
access by name an element of an array or collection when no such named
element exists. For example, in your code you have

With Sheets("Sheet1").Range("A:A")

If there is no worksheet named "Sheet1", you'll get an error 9 when
you attempt to access "Sheet1". My guess is that your user has no
sheet named "Sheet1".

If you always want to use the first worksheet in the workbook, you can
use

With Worksheets(1).Range("A:A")

If the sheet isn't predictable by its position, you'll need to require
the user to be on the appropriate sheet when running the code, in
which case you can use

With ActiveSheet.Range("A:A")

Otherwise, you'll need to prompt the user for the appropriate sheet.


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Fri, 5 Dec 2008 14:18:52 -0800, Steve
<(E-Mail Removed)> wrote:

>Sub Find_Todays_Date()
>Dim FindString As Date
>Dim Rng As Range
>FindString = CLng(Date)
>With Sheets("Sheet1").Range("A:A")
>Set Rng = .Find(What:=FindString, _
>After:=.Cells(.Cells.Count), _
>LookIn:=xlFormulas, _
>LookAt:=xlWhole, _
>SearchOrder:=xlByRows, _
>SearchDirection:=xlNext, _
>MatchCase:=False)
>If Not Rng Is Nothing Then
>Application.Goto Rng, True
>Else
>MsgBox "Nothing found"
>End If
>End With
>End Sub
>
>
>This is my code. It is supposed to goto the date when executed. It works
>fine on my machine, but I tried putting it on someone else's and it gave me a
>data error message. It said something like the subprocedure is out of range.
>It was Data Error 9. I've checked the refrence style setting in the options
>pannel and they are the same on both machines. We are both using MS 2003, but
>come to think of it Im not sure which SP the other one is using... Any ideas?

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro subprocedure orquidea Microsoft Excel Misc 6 13th May 2008 01:10 AM
Macro error, range object need data? =?Utf-8?B?RGFuaWVs?= Microsoft Excel Charting 1 15th Jun 2007 11:27 AM
Passing an Array created in a Function or Subprocedure back to the calling Subprocedure Cloudfall Microsoft Excel Discussion 7 17th Mar 2006 12:56 AM
Cannot expand data range - Error message =?Utf-8?B?U211ZGdlcg==?= Microsoft Access External Data 8 1st Oct 2004 03:31 PM
Passing range to subprocedure - maybe? Mike Gerbracht Microsoft Excel Programming 2 26th Jul 2003 02:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:24 AM.