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

I'm getting a Type Mismatch error at the + on this line. I'm not exactly
sure what's supposed to be done here (I'm sure it's searching for something),
so don't know why the + is here.

Selection.Find(What:="" + myVar + "", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

It's dimensioned as follows:

Public myVar() As String

Can someone assist?

Thanks,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Type Mismatch error

What it is looking for is the string
" + myVar + "
which makes absolutely no sense based on the declaration. I assume you did
not write it? As a guess someone was recording a macro and typed in " + myVar
+ " in the find box. You need to create a loop which traveres all of the
items in the array and do the find that way. Based on the code you have
posted in the past you should be able to manage that (or get darned close).
Make sure that you set a range object to the resutls of the find and then
determine if the object is nothing...

If you wnat more help just reply.
--
HTH...

Jim Thomlinson


"Barb Reinhardt" wrote:

I'm getting a Type Mismatch error at the + on this line. I'm not exactly
sure what's supposed to be done here (I'm sure it's searching for something),
so don't know why the + is here.

Selection.Find(What:="" + myVar + "", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

It's dimensioned as follows:

Public myVar() As String

Can someone assist?

Thanks,
Barb Reinhardt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 417
Default Type Mismatch error

You have dimensioned myVar as an array of strings. If so, then your code
should probably be:

Selection.Find(What:=myVar(1), _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If myVar is a single string, then it should have been declared like so:

Dim myVar As String

Assuming the 2nd case, I would rewrite this code like the following:

Dim myVar As String
Dim rngFindResult As Range

Set rngFindResult = Selection.Find(What:=myVar, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If rngFindResult Is Nothing _
Then
'Error message here?
Else
rngFindResult.Activate
End If

Or, maybe the What parameter should be:

What:="" & myVar & "",

....if you need to have a single double apostrophe appended onto the front
and back of myVar for some reason (I notice that your Find method is
looking in formulas).

In general, if you are concantenating strings together, then use the
ampersand character ("&"), not the plus sign ("+").
If you need to convert a value to a string, then you might have to use
something like:

CStr(myVar)

You might even add another variable and get it set to exactly what the Find
method is searching for (extra double quotes and all). Then you can
single-step through the code and inspect the value of this new variable in
the Locals window.
--
Regards,
Bill Renaud



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

I've subsequently found that the procedure with the error isn't even used.

Thanks for your assistance.

Barb Reinhardt



"Jim Thomlinson" wrote:

What it is looking for is the string
" + myVar + "
which makes absolutely no sense based on the declaration. I assume you did
not write it? As a guess someone was recording a macro and typed in " + myVar
+ " in the find box. You need to create a loop which traveres all of the
items in the array and do the find that way. Based on the code you have
posted in the past you should be able to manage that (or get darned close).
Make sure that you set a range object to the resutls of the find and then
determine if the object is nothing...

If you wnat more help just reply.
--
HTH...

Jim Thomlinson


"Barb Reinhardt" wrote:

I'm getting a Type Mismatch error at the + on this line. I'm not exactly
sure what's supposed to be done here (I'm sure it's searching for something),
so don't know why the + is here.

Selection.Find(What:="" + myVar + "", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

It's dimensioned as follows:

Public myVar() As String

Can someone assist?

Thanks,
Barb Reinhardt

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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Conditional Formatting - Run Time Error '13' Type Mismatch Error ksp Excel Programming 0 July 11th 06 07:06 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Help with odd type mismatch error George Raft Excel Programming 3 December 31st 04 07:21 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 03:00 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"