Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Type mismatch error in Find method

This line:

Set q = .Find(stName, After:=Range("$C$2"))

In the code below throws the error of type mismatch because it does not like
the After:=Range("$C$2"). I have subsequently altered the code as shown
below to make it run properly, but I would appreciate it if someone can
provide an explanation of how the type is mismatched so I can avoid these
goof-ups in the future.


Dim stName As Variant, x As Variant
Worksheets(1).Activate
lr1 = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
lr2 = Worksheets(3).Cells(Rows.Count, 1).End(xlUp).Row
n = 2
If Worksheets(3).Range("$A$2") = "" Then
With Worksheets(1)
For i = 2 To lr1
If Cells(i, 3) < .Cells(i, 3).Offset(1, 0) Then
.Cells(i, 3).Copy Worksheets(3).Cells(n, 1)
n = n + 1
End If
Next i
End With
End If
Set SrchRng = Worksheets(3).Range("$A$2:$A" & lr2)
Set FndRng = Worksheets(1).Range("$C$2:$C" & lr1)
For Each c In SrchRng
If Not c Is Nothing Then
stName = c.Value
stRng = c.Address
With Worksheets(1).Range("$C$2:$C" & lr1)
Set q = .Find(stName, After:=Range(stRng).Offset(0, 2)) '
This works
If Not q Is Nothing Then
x = q.Value
Worksheets(3).Range(stRng).Offset(0, 1) =
Application.CountIf(FndRng, x)
End If
End With
End If
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Type mismatch error in Find method


Try qualifying the range with the correct worksheet...
After:=Worksheet(?).Range("$C$2")
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"JLGWhiz"
wrote in message
This line:
Set q = .Find(stName, After:=Range("$C$2"))

In the code below throws the error of type mismatch because it does not like
the After:=Range("$C$2"). I have subsequently altered the code as shown
below to make it run properly, but I would appreciate it if someone can
provide an explanation of how the type is mismatched so I can avoid these
goof-ups in the future.


Dim stName As Variant, x As Variant
Worksheets(1).Activate
lr1 = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
lr2 = Worksheets(3).Cells(Rows.Count, 1).End(xlUp).Row
n = 2
If Worksheets(3).Range("$A$2") = "" Then
With Worksheets(1)
For i = 2 To lr1
If Cells(i, 3) < .Cells(i, 3).Offset(1, 0) Then
.Cells(i, 3).Copy Worksheets(3).Cells(n, 1)
n = n + 1
End If
Next i
End With
End If
Set SrchRng = Worksheets(3).Range("$A$2:$A" & lr2)
Set FndRng = Worksheets(1).Range("$C$2:$C" & lr1)
For Each c In SrchRng
If Not c Is Nothing Then
stName = c.Value
stRng = c.Address
With Worksheets(1).Range("$C$2:$C" & lr1)
Set q = .Find(stName, After:=Range(stRng).Offset(0, 2)) '
This works
If Not q Is Nothing Then
x = q.Value
Worksheets(3).Range(stRng).Offset(0, 1) =
Application.CountIf(FndRng, x)
End If
End With
End If
Next
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
FIND type mismatch error, but don't see it KathyC Excel Worksheet Functions 7 November 14th 06 03:59 PM
Type mismatch error on Find [email protected] Excel Programming 4 November 3rd 06 01:39 AM
Type Mismatch Error when using InputBox Method Anolan Excel Programming 1 November 22nd 05 07:35 PM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM


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