Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Error: Type mismatch

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
youu917@gmail.com - 11 Mar 2008 10:31 GMT
i have a vba code included the following:
shortest = count(1)
For r = 1 To 200
If count(r) < shortest And count(r) > 0 Then
shortest = count(r)
End If
Next
   Rows("shortest:shortest").Select
   Selection.Cut
   Rows("1:1").Select
   Selection.Insert Shift:=xlDown

However, when i try to run the code, the debugger promt an error
message said : type mismatch and then highlight the code:
Rows("shortest:shortest").select.
I declared "shortest" as variant.

Can any pro point out my mistake?Thank you very much
Gary''s Student - 11 Mar 2008 10:58 GMT
You need the value of shortest in the Select, not just a string.

Instead of:

Rows("shortest:shortest").Select

use:

Rows(shortest & ":" & shortest).Select
Signature

Gary''s Student - gsnu200772

> i have a vba code included the following:
> shortest = count(1)
[quoted text clipped - 14 lines]
>
> Can any pro point out my mistake?Thank you very much
youu917@gmail.com - 12 Mar 2008 01:57 GMT
On Mar 11, 5:58 pm, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> You need the value of shortest in the Select, not just a string.
>
[quoted text clipped - 29 lines]
>
> - Show quoted text -

thank you
youu917@gmail.com - 12 Mar 2008 02:11 GMT
On Mar 11, 5:58 pm, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> You need the value of shortest in the Select, not just a string.
>
[quoted text clipped - 29 lines]
>
> - Show quoted text -

Sorry, i found that the code is a bit weird and unstable. i try to run
it at the first time, it works. However, i try to run second time, it
prompt out the "type mismatch" error message again
paul.robinson@it-tallaght.ie - 11 Mar 2008 10:58 GMT
Hi
"shortest:shortest" is a piece of text - VBA does not delve inside the
text string to extract the variables. You need

shortest & ":" & shortest

The & character will force this to be a text string with shortest
replaced with its numerical value.
regards
Paul

On Mar 11, 9:31 am, youu...@gmail.com wrote:
> i have a vba code included the following:
> shortest = count(1)
[quoted text clipped - 14 lines]
>
> Can any pro point out my mistake?Thank you very much
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.