#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 333
Default Match Error

Hi,

I am tryihg to compare the worksheet names between two worksheets to a list
on the main page. If it does not exist on the main page list the sheet name
is placed on the maintenance page. I get a method range of object worksheet
failed message. I've been trying to find an explanation with not luck. What
does this error mean and how do I fix it?

Also, I've sometimes seen the Set cleared with Set Whatever = Nothing, but I
usually don't see it. What is the best practice and what are the
ramifications if it's done vs not done?

Thanks for your help.

Dim ws As Worksheet
Dim FirstIndex As Long
Dim LastIndex As Long
Dim Nuserow As Long
Dim Lusedrow As Long
Dim CellRange As Range

'get the last cell on Main Page for the sheet names in BD
Lusedrow = MainPagepg.Cells(Rows.Count, "BD").End(xlUp).Row

Set CellRange = MainPagepg.Range("BD13:BD" & Lusedrow)
FirstIndex = Firstpg.Index
LastIndex = Lastpg.Index
ShNotLogged = False

For Each ws In ThisWorkbook.Worksheets
If ws.Index FirstIndex Then
If ws.Index < LastIndex Then
If (IsError(Application.WorksheetFunction.Match(ws.Na me,
CellRange, 0))) Then
With Maintenancepg
'find the next empty cell on maintenance page
Nuserow = Maintenancepg.Cells(Rows.Count,
"B").End(xlUp).Row + 1
'save the missing sheet name
Maintenancepg.Cells(Nuserow, 2).Value = ws.Name
ShNotLogged = True
End With
End If
End If
End If
Next ws
--
Thanks for your help.
Karen53
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Match Error

Try changing this line:
If (IsError(Application.WorksheetFunction.Match(ws.Na me, CellRange, 0))) Then
to
If (IsError(Application.Match(ws.Name, CellRange, 0))) Then
(removed .worksheetfunction)

Application.vlookup will return a value that you can test with iserror().
Application.worksheetfunction.vlookup causes a runtime error if there's an
error.

Are you asking about resetting procedural object variables at the end of the
procedure?

sub somesub()
Dim Something as Object
'''lots of code
Set something = nothing
End sub

If yes, then I don't bother. When the procedure ends, VBA will clean up for me.

On the other hand, if that object variable is persistent:

Option explicit
dim something as object
sub somesub()
set something = someobjecthere
'''lots of code
Set something = nothing
End sub

I'd reset the variable only if I wanted to lose what it pointed to.




Karen53 wrote:

Hi,

I am tryihg to compare the worksheet names between two worksheets to a list
on the main page. If it does not exist on the main page list the sheet name
is placed on the maintenance page. I get a method range of object worksheet
failed message. I've been trying to find an explanation with not luck. What
does this error mean and how do I fix it?

Also, I've sometimes seen the Set cleared with Set Whatever = Nothing, but I
usually don't see it. What is the best practice and what are the
ramifications if it's done vs not done?

Thanks for your help.

Dim ws As Worksheet
Dim FirstIndex As Long
Dim LastIndex As Long
Dim Nuserow As Long
Dim Lusedrow As Long
Dim CellRange As Range

'get the last cell on Main Page for the sheet names in BD
Lusedrow = MainPagepg.Cells(Rows.Count, "BD").End(xlUp).Row

Set CellRange = MainPagepg.Range("BD13:BD" & Lusedrow)
FirstIndex = Firstpg.Index
LastIndex = Lastpg.Index
ShNotLogged = False

For Each ws In ThisWorkbook.Worksheets
If ws.Index FirstIndex Then
If ws.Index < LastIndex Then
If (IsError(Application.WorksheetFunction.Match(ws.Na me,
CellRange, 0))) Then
With Maintenancepg
'find the next empty cell on maintenance page
Nuserow = Maintenancepg.Cells(Rows.Count,
"B").End(xlUp).Row + 1
'save the missing sheet name
Maintenancepg.Cells(Nuserow, 2).Value = ws.Name
ShNotLogged = True
End With
End If
End If
End If
Next ws
--
Thanks for your help.
Karen53


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 333
Default Match Error

Thank you, Dave. That was what I was asking.

It's working now. Thanks!
--
Thanks for your help.
Karen53


"Dave Peterson" wrote:

Try changing this line:
If (IsError(Application.WorksheetFunction.Match(ws.Na me, CellRange, 0))) Then
to
If (IsError(Application.Match(ws.Name, CellRange, 0))) Then
(removed .worksheetfunction)

Application.vlookup will return a value that you can test with iserror().
Application.worksheetfunction.vlookup causes a runtime error if there's an
error.

Are you asking about resetting procedural object variables at the end of the
procedure?

sub somesub()
Dim Something as Object
'''lots of code
Set something = nothing
End sub

If yes, then I don't bother. When the procedure ends, VBA will clean up for me.

On the other hand, if that object variable is persistent:

Option explicit
dim something as object
sub somesub()
set something = someobjecthere
'''lots of code
Set something = nothing
End sub

I'd reset the variable only if I wanted to lose what it pointed to.




Karen53 wrote:

Hi,

I am tryihg to compare the worksheet names between two worksheets to a list
on the main page. If it does not exist on the main page list the sheet name
is placed on the maintenance page. I get a method range of object worksheet
failed message. I've been trying to find an explanation with not luck. What
does this error mean and how do I fix it?

Also, I've sometimes seen the Set cleared with Set Whatever = Nothing, but I
usually don't see it. What is the best practice and what are the
ramifications if it's done vs not done?

Thanks for your help.

Dim ws As Worksheet
Dim FirstIndex As Long
Dim LastIndex As Long
Dim Nuserow As Long
Dim Lusedrow As Long
Dim CellRange As Range

'get the last cell on Main Page for the sheet names in BD
Lusedrow = MainPagepg.Cells(Rows.Count, "BD").End(xlUp).Row

Set CellRange = MainPagepg.Range("BD13:BD" & Lusedrow)
FirstIndex = Firstpg.Index
LastIndex = Lastpg.Index
ShNotLogged = False

For Each ws In ThisWorkbook.Worksheets
If ws.Index FirstIndex Then
If ws.Index < LastIndex Then
If (IsError(Application.WorksheetFunction.Match(ws.Na me,
CellRange, 0))) Then
With Maintenancepg
'find the next empty cell on maintenance page
Nuserow = Maintenancepg.Cells(Rows.Count,
"B").End(xlUp).Row + 1
'save the missing sheet name
Maintenancepg.Cells(Nuserow, 2).Value = ws.Name
ShNotLogged = True
End With
End If
End If
End If
Next ws
--
Thanks for your help.
Karen53


--

Dave Peterson

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
match error Belinda7237 Excel Worksheet Functions 3 August 8th 08 04:20 PM
Getting a MATCH error Lulu Montiel[_2_] Excel Discussion (Misc queries) 1 April 4th 08 05:44 PM
Error Type Mis Match Error 13 Gordon[_2_] Excel Programming 1 December 20th 04 02:40 PM
Formula MATCH error peterfc2 Excel Worksheet Functions 1 November 8th 04 05:07 PM
VBA Match Error tbieri Excel Programming 1 June 25th 04 11:24 PM


All times are GMT +1. The time now is 03:38 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"