Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Type Mismatch

I get a type mismatch with the first code and still doesnt run with second,
clearly missing something, help is much appreciated

with worksheets("sheet1")
If Application.match(.Cells(i, 2),
wipwkbk.Worksheets("Live").Range("b1:b18"), 0) 0 Then
.Cells(i, 1).EntireRow.Copy
Destination:=Worksheets("Sheet7").Cells(j,1)

OR

with worksheets("sheet1")
If Application.match(.Cells(i, 2),
wipwkbk.Worksheets("Live").Range("b1:b18"), 0) Then
.Cells(i, 1).EntireRow.Copy Destination:=Worksheets("Sheet7").Cells(j,1)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Type Mismatch

Teresa,

I tidied it up a bit and that worked fine for me

With Worksheets("sheet1")
If Application.Match(.Cells(i, 2), _
wipwkbk.Worksheets("Live").Range("b1:b18"), 0) 0 Then
.Cells(i, 1).EntireRow.Copy
Destination:=Worksheets("Sheet7").Cells(j, 1)
End If
End With

What have you got in wipwkbk, i and j variables?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"teresa" wrote in message
...
I get a type mismatch with the first code and still doesnt run with

second,
clearly missing something, help is much appreciated

with worksheets("sheet1")
If Application.match(.Cells(i, 2),
wipwkbk.Worksheets("Live").Range("b1:b18"), 0) 0 Then
.Cells(i, 1).EntireRow.Copy
Destination:=Worksheets("Sheet7").Cells(j,1)

OR

with worksheets("sheet1")
If Application.match(.Cells(i, 2),
wipwkbk.Worksheets("Live").Range("b1:b18"), 0) Then
.Cells(i, 1).EntireRow.Copy

Destination:=Worksheets("Sheet7").Cells(j,1)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Type Mismatch

problem is that MATCH, anf the Lookup functions error out if there's no
match...so trap them in a "safe" function....



With Worksheets("sheet1")
If MyMatch(.Cells(i, 2).Value, Worksheets("Live").Range("b1:b18")) Then
.Cells(i, 1).EntireRow.Copy
Destination:=Worksheets("Sheet7").Cells(j, 1)

End If
End With

End Sub

Function MyMatch(what As String, where As Range) As Boolean
On Error Resume Next
Dim result As Long
result = Application.WorksheetFunction.Match(what, where, 0)
On Error GoTo 0
MyMatch = (result 0)
End Function


"teresa" wrote:

I get a type mismatch with the first code and still doesnt run with second,
clearly missing something, help is much appreciated

with worksheets("sheet1")
If Application.match(.Cells(i, 2),
wipwkbk.Worksheets("Live").Range("b1:b18"), 0) 0 Then
.Cells(i, 1).EntireRow.Copy
Destination:=Worksheets("Sheet7").Cells(j,1)

OR

with worksheets("sheet1")
If Application.match(.Cells(i, 2),
wipwkbk.Worksheets("Live").Range("b1:b18"), 0) Then
.Cells(i, 1).EntireRow.Copy Destination:=Worksheets("Sheet7").Cells(j,1)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Type Mismatch

Well Teresa,

From where did you get Application.Match ?

Try following code instead :

If Not wipwkbk.Worksheets("Live").Range("b1:b18") _
.Find(.Cells(i, 2)) Is Nothing Then
.Cells(i, 1).EntireRow.Copy _
Destination:=Worksheets("Sheet7").Cells(j, 1)
End If

Sharad

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Type Mismatch

Application.Match

often used "shortcut" for worksheet functions
eg
Application.VLookUp
instead of Application.WorksheetFunction.VLookUp

NOT SAFE. Always use the full syntax.

"Sharad" wrote:

Well Teresa,

From where did you get Application.Match ?

Try following code instead :

If Not wipwkbk.Worksheets("Live").Range("b1:b18") _
.Find(.Cells(i, 2)) Is Nothing Then
.Cells(i, 1).EntireRow.Copy _
Destination:=Worksheets("Sheet7").Cells(j, 1)
End If

Sharad

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Type Mismatch

Thanks Patrick,
I already guessed it from your earlier post.
Sharad
"Patrick Molloy" wrote in message
...
Application.Match

often used "shortcut" for worksheet functions
eg
Application.VLookUp
instead of Application.WorksheetFunction.VLookUp

NOT SAFE. Always use the full syntax.

"Sharad" wrote:

Well Teresa,

From where did you get Application.Match ?

Try following code instead :

If Not wipwkbk.Worksheets("Live").Range("b1:b18") _
.Find(.Cells(i, 2)) Is Nothing Then
.Cells(i, 1).EntireRow.Copy _
Destination:=Worksheets("Sheet7").Cells(j, 1)
End If

Sharad

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Type Mismatch

I like to use application.match()

dim res as variant
with worksheets("sheet1")
res = Application.match(.Cells(i, 2), _
wipwkbk.Worksheets("Live").Range("b1:b18"), 0)

if iserror(res) then
'what should happen
else
if isnumeric(res) then
if res 0 then
.cells(i,1).entirerow.copy _
Destination:=Worksheets("Sheet7").Cells(j,1)
else
'do nothing???
end if
else
'do nothing
end if
end if
end with

teresa wrote:

I get a type mismatch with the first code and still doesnt run with second,
clearly missing something, help is much appreciated

with worksheets("sheet1")
If Application.match(.Cells(i, 2),
wipwkbk.Worksheets("Live").Range("b1:b18"), 0) 0 Then
.Cells(i, 1).EntireRow.Copy
Destination:=Worksheets("Sheet7").Cells(j,1)

OR

with worksheets("sheet1")
If Application.match(.Cells(i, 2),
wipwkbk.Worksheets("Live").Range("b1:b18"), 0) Then
.Cells(i, 1).EntireRow.Copy Destination:=Worksheets("Sheet7").Cells(j,1)


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Type Mismatch

Patrick Molloy wrote:
Application.Match

often used "shortcut" for worksheet functions
eg
Application.VLookUp
instead of Application.WorksheetFunction.VLookUp

NOT SAFE. Always use the full syntax.


Patrick,

Can you elaborate on that. I never use WorksheetFunction so I can trap the
errors similar to what Dave did later in this thread. I always thought is
was a personal preference, but I'd be interested to know if there's
something I'm not considering.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Type Mismatch

One thing that both you and I miss is the intellisense that you get with
..worksheetfunction, but I'm willing to live with that loss.



Dick Kusleika wrote:

Patrick Molloy wrote:
Application.Match

often used "shortcut" for worksheet functions
eg
Application.VLookUp
instead of Application.WorksheetFunction.VLookUp

NOT SAFE. Always use the full syntax.


Patrick,

Can you elaborate on that. I never use WorksheetFunction so I can trap the
errors similar to what Dave did later in this thread. I always thought is
was a personal preference, but I'd be interested to know if there's
something I'm not considering.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Type Mismatch

I still get it. I use WorksheetFunction when writing and then delete it.
The only thing I don't like is trying to figure out where I want to break
long lines.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Dave Peterson wrote:
One thing that both you and I miss is the intellisense that you get
with .worksheetfunction, but I'm willing to live with that loss.



Dick Kusleika wrote:

Patrick Molloy wrote:
Application.Match

often used "shortcut" for worksheet functions
eg
Application.VLookUp
instead of Application.WorksheetFunction.VLookUp

NOT SAFE. Always use the full syntax.


Patrick,

Can you elaborate on that. I never use WorksheetFunction so I can
trap the errors similar to what Dave did later in this thread. I
always thought is was a personal preference, but I'd be interested
to know if there's something I'm not considering.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Type Mismatch

the idea of using a "safe" function is to use the on error method to trap
errors from functions like VLOOKUP and MATCH that raise errors when they
fail to find th elookup item and this then means that your usual error
handling remains much cleaner...IF you have them :)

"Dick Kusleika" wrote in message
...
I still get it. I use WorksheetFunction when writing and then delete it.
The only thing I don't like is trying to figure out where I want to break
long lines.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Dave Peterson wrote:
One thing that both you and I miss is the intellisense that you get
with .worksheetfunction, but I'm willing to live with that loss.



Dick Kusleika wrote:

Patrick Molloy wrote:
Application.Match

often used "shortcut" for worksheet functions
eg
Application.VLookUp
instead of Application.WorksheetFunction.VLookUp

NOT SAFE. Always use the full syntax.


Patrick,

Can you elaborate on that. I never use WorksheetFunction so I can
trap the errors similar to what Dave did later in this thread. I
always thought is was a personal preference, but I'd be interested
to know if there's something I'm not considering.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com





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
Type Mismatch [email protected] Excel Worksheet Functions 1 May 16th 07 03:29 PM
Type Mismatch Rockee052[_60_] Excel Programming 4 March 7th 04 12:12 AM
Type mismatch Stuart[_5_] Excel Programming 4 February 19th 04 07:54 PM
Type Mismatch Edgar[_3_] Excel Programming 4 February 13th 04 03:55 PM


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