Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default runtime error 13

I have a list of sorted names (some repeat) and am trying to find the first
row a name occurs and the last row a name occurs. Sometimes the name
(DBName) is not in the list. When the name is not in the list, I get the
runtime error 13. I guess its because #N/A is being assigned to
DBRowNumFirst. How do I get around this problem?


Dim DBName As String
Dim DBRowNumFirst, DBRowNumLast, DBRows As Integer

DataRows = Cells(Rows.Count, 1).End(xlUp).Row
DBRowNumFirst = Application.Match(DBName, Range("A3:A" +
CStr(DataRows)), 0)
DBRowNumLast = Application.Match(DBName, Range("A3:A" + CStr(DataRows)),
1)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default runtime error 13

Even though DBRowNumFirst & DBRowNumLast are of type variant (not integer as
you might supect) they still will not accept error values. You could do is
something like this...

Dim DBName As String
Dim DBRowNumFirst as Long 'use long as int only holds 32k
Dim DBRowNumLast as Long 'and long is actually more efficent
Dim DBRows As Long

DataRows = Cells(Rows.Count, 1).End(xlUp).Row
on error resume next
DBRowNumFirst = Application.Match(DBName, Range("A3:A" & DataRows), 0)
DBRowNumLast = Application.Match(DBName, Range("A3:A" & DataRows), 1)
On error goto 0
if DBRowNumFirst = 0 or DBRowNumLast = 0 then msgbox "???"

--
HTH...

Jim Thomlinson


"Scott" wrote:

I have a list of sorted names (some repeat) and am trying to find the first
row a name occurs and the last row a name occurs. Sometimes the name
(DBName) is not in the list. When the name is not in the list, I get the
runtime error 13. I guess its because #N/A is being assigned to
DBRowNumFirst. How do I get around this problem?


Dim DBName As String
Dim DBRowNumFirst, DBRowNumLast, DBRows As Integer

DataRows = Cells(Rows.Count, 1).End(xlUp).Row
DBRowNumFirst = Application.Match(DBName, Range("A3:A" +
CStr(DataRows)), 0)
DBRowNumLast = Application.Match(DBName, Range("A3:A" + CStr(DataRows)),
1)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default runtime error 13

I also had this right above the code

On Error GoTo nodata

but it never goes there, I just get the runtime error 13 at
DBRowNumFirst = Application.Match(DBName, Range("A3:A" + CStr(DataRows)), 0)

I ran your example and it worked. In the debugger this is what it had

: DBRowNumFirst : Error 2042 : Variant/Error
--------------------------------------------------------------------------------------------------

"Jim Thomlinson" wrote:

Even though DBRowNumFirst & DBRowNumLast are of type variant (not integer as
you might supect) they still will not accept error values. You could do is
something like this...

Dim DBName As String
Dim DBRowNumFirst as Long 'use long as int only holds 32k
Dim DBRowNumLast as Long 'and long is actually more efficent
Dim DBRows As Long

DataRows = Cells(Rows.Count, 1).End(xlUp).Row
on error resume next
DBRowNumFirst = Application.Match(DBName, Range("A3:A" & DataRows), 0)
DBRowNumLast = Application.Match(DBName, Range("A3:A" & DataRows), 1)
On error goto 0
if DBRowNumFirst = 0 or DBRowNumLast = 0 then msgbox "???"

--
HTH...

Jim Thomlinson


"Scott" wrote:

I have a list of sorted names (some repeat) and am trying to find the first
row a name occurs and the last row a name occurs. Sometimes the name
(DBName) is not in the list. When the name is not in the list, I get the
runtime error 13. I guess its because #N/A is being assigned to
DBRowNumFirst. How do I get around this problem?


Dim DBName As String
Dim DBRowNumFirst, DBRowNumLast, DBRows As Integer

DataRows = Cells(Rows.Count, 1).End(xlUp).Row
DBRowNumFirst = Application.Match(DBName, Range("A3:A" +
CStr(DataRows)), 0)
DBRowNumLast = Application.Match(DBName, Range("A3:A" + CStr(DataRows)),
1)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default runtime error 13

I can not comment on code that is not posted as to why it might not be
working.
--
HTH...

Jim Thomlinson


"Scott" wrote:

I also had this right above the code

On Error GoTo nodata

but it never goes there, I just get the runtime error 13 at
DBRowNumFirst = Application.Match(DBName, Range("A3:A" + CStr(DataRows)), 0)

I ran your example and it worked. In the debugger this is what it had

: DBRowNumFirst : Error 2042 : Variant/Error
--------------------------------------------------------------------------------------------------

"Jim Thomlinson" wrote:

Even though DBRowNumFirst & DBRowNumLast are of type variant (not integer as
you might supect) they still will not accept error values. You could do is
something like this...

Dim DBName As String
Dim DBRowNumFirst as Long 'use long as int only holds 32k
Dim DBRowNumLast as Long 'and long is actually more efficent
Dim DBRows As Long

DataRows = Cells(Rows.Count, 1).End(xlUp).Row
on error resume next
DBRowNumFirst = Application.Match(DBName, Range("A3:A" & DataRows), 0)
DBRowNumLast = Application.Match(DBName, Range("A3:A" & DataRows), 1)
On error goto 0
if DBRowNumFirst = 0 or DBRowNumLast = 0 then msgbox "???"

--
HTH...

Jim Thomlinson


"Scott" wrote:

I have a list of sorted names (some repeat) and am trying to find the first
row a name occurs and the last row a name occurs. Sometimes the name
(DBName) is not in the list. When the name is not in the list, I get the
runtime error 13. I guess its because #N/A is being assigned to
DBRowNumFirst. How do I get around this problem?


Dim DBName As String
Dim DBRowNumFirst, DBRowNumLast, DBRows As Integer

DataRows = Cells(Rows.Count, 1).End(xlUp).Row
DBRowNumFirst = Application.Match(DBName, Range("A3:A" +
CStr(DataRows)), 0)
DBRowNumLast = Application.Match(DBName, Range("A3:A" + CStr(DataRows)),
1)

Reply
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' application or object defined error Janis Excel Programming 4 November 18th 09 03:01 PM
runtime error 13 - type mismatch error in Excel 97 on Citrix Kevin Maher Excel Programming 7 March 8th 08 11:48 AM
runtime error '1004' application or object defined error. Please help deej Excel Programming 0 August 1st 07 09:26 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM


All times are GMT +1. The time now is 06:18 PM.

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

About Us

"It's about Microsoft Excel"