Error: Type mismatch

Y

youu917

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
 
G

Gary''s Student

You need the value of shortest in the Select, not just a string.

Instead of:

Rows("shortest:shortest").Select

use:

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

paul.robinson

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
 
Y

youu917

You need the value of shortest in the Select, not just a string.

Instead of:

Rows("shortest:shortest").Select

use:

Rows(shortest & ":" & shortest).Select
--
Gary''s Student - gsnu200772







- Show quoted text -

thank you
 
Y

youu917

You need the value of shortest in the Select, not just a string.

Instead of:

Rows("shortest:shortest").Select

use:

Rows(shortest & ":" & shortest).Select
--
Gary''s Student - gsnu200772







- 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top