#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default macro-match function

Hello everybody
The following macro i copied from VB help
Sub FindFirst()
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
End Sub

I want to insert a condition, if the number is not available (function
returns error) then exit. Inthis case the macro is returning error 1004.
How to modify the code?
With regards
Sreedhar



  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default macro-match function

This would work

Sub FindFirst()
On Error GoTo Endit
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
Endit:
End Sub

Rob

"yshridhar" wrote in message
...
Hello everybody
The following macro i copied from VB help
Sub FindFirst()
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
End Sub

I want to insert a condition, if the number is not available (function
returns error) then exit. Inthis case the macro is returning error 1004.
How to modify the code?
With regards
Sreedhar





  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default macro-match function

Thank you Rob. One more clarification. How to insert msgbox OnError.
With regards
Sreedhar

"RobN" wrote:

This would work

Sub FindFirst()
On Error GoTo Endit
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
Endit:
End Sub

Rob

"yshridhar" wrote in message
...
Hello everybody
The following macro i copied from VB help
Sub FindFirst()
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
End Sub

I want to insert a condition, if the number is not available (function
returns error) then exit. Inthis case the macro is returning error 1004.
How to modify the code?
With regards
Sreedhar






  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 230
Default macro-match function

yshridhar,

Hope this is what you're after.

Sub FindFirst()
On Error GoTo Endit
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
Exit Sub
Endit:
MsgBox "No match found!"
End Sub

Rob

"yshridhar" wrote in message
...
Thank you Rob. One more clarification. How to insert msgbox OnError.
With regards
Sreedhar

"RobN" wrote:

This would work

Sub FindFirst()
On Error GoTo Endit
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
Endit:
End Sub

Rob

"yshridhar" wrote in message
...
Hello everybody
The following macro i copied from VB help
Sub FindFirst()
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
End Sub

I want to insert a condition, if the number is not available (function
returns error) then exit. Inthis case the macro is returning error
1004.
How to modify the code?
With regards
Sreedhar








  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default macro-match function

Thank you Rob. This is what i want.
With regards
Sreedhar

"RobN" wrote:

yshridhar,

Hope this is what you're after.

Sub FindFirst()
On Error GoTo Endit
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
Exit Sub
Endit:
MsgBox "No match found!"
End Sub

Rob

"yshridhar" wrote in message
...
Thank you Rob. One more clarification. How to insert msgbox OnError.
With regards
Sreedhar

"RobN" wrote:

This would work

Sub FindFirst()
On Error GoTo Endit
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
Endit:
End Sub

Rob

"yshridhar" wrote in message
...
Hello everybody
The following macro i copied from VB help
Sub FindFirst()
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
End Sub

I want to insert a condition, if the number is not available (function
returns error) then exit. Inthis case the macro is returning error
1004.
How to modify the code?
With regards
Sreedhar











  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default macro-match function

You could also use:

Sub FindFirst()
dim myVar as variant
myvar = Application.Match(9, Worksheets(1).Range("A1:A10"), 0)
if iserror(myvar) then
msgbox "Error"
else
MsgBox myvar
end if
End Sub

yshridhar wrote:

Hello everybody
The following macro i copied from VB help
Sub FindFirst()
myvar = Application.WorksheetFunction.Match(9,
Worksheets(1).Range("A1:A10"), 0)
MsgBox myvar
End Sub

I want to insert a condition, if the number is not available (function
returns error) then exit. Inthis case the macro is returning error 1004.
How to modify the code?
With regards
Sreedhar


--

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
how can we get unique values in match function for same match key. Xcel[_2_] Excel Worksheet Functions 11 December 7th 07 08:13 PM
index match array function-returning only first match, need last. Julie Olsen Excel Worksheet Functions 3 December 29th 06 12:50 AM
Match as well as does not match array function Vikram Dhemare Excel Discussion (Misc queries) 7 April 25th 06 09:15 AM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM


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