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

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Error: Type mismatch

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


" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Error: Type mismatch

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, wrote:
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Error: Type mismatch

On Mar 11, 5:58*pm, Gary''s Student
wrote:
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



" wrote:
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 :typemismatchand then highlight the code:
Rows("shortest:shortest").select.
I declared "shortest" as variant.


Can any pro point out my mistake?Thank you very much- Hide quoted text -


- Show quoted text -


thank you
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Error: Type mismatch

On Mar 11, 5:58*pm, Gary''s Student
wrote:
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



" wrote:
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 :typemismatchand then highlight the code:
Rows("shortest:shortest").select.
I declared "shortest" as variant.


Can any pro point out my mistake?Thank you very much- Hide quoted text -


- 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
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
runtime error 13 - type mismatch error in Excel 97 on Citrix Kevin Maher Excel Programming 7 March 8th 08 11:48 AM
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
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 02:48 AM.

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"