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

Can anyone tell me why this produces Run-time error 13: Type mismatch?

Thanks in advance.

----------

Option Explicit
Private Sub testloop()

Dim lstrow As Long
Dim i As Long
Dim agtname As String

lstrow = Range("a" & Rows.Count).End(xlUp).Rows
For i = 2 To lstrow
agtname = Range("a" & i).Value ' *** also tried .Text & still got error
MsgBox "Current Name is " & agtname
i = i + 1
Next i
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Type mismatch

It is not that you assignment of the range value (or text) is wrong you
just need to change your last row code to this......

lstrow = Cells(Rows.Count, "A").End(xlUp).Row

Cheers
Nigel

"Patti" wrote in message
...
Can anyone tell me why this produces Run-time error 13: Type mismatch?

Thanks in advance.

----------

Option Explicit
Private Sub testloop()

Dim lstrow As Long
Dim i As Long
Dim agtname As String

lstrow = Range("a" & Rows.Count).End(xlUp).Rows
For i = 2 To lstrow
agtname = Range("a" & i).Value ' *** also tried .Text & still got

error
MsgBox "Current Name is " & agtname
i = i + 1
Next i
End Sub




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

In addition to Nigels comment are you sure you need the line i = i +
1
as it is "incrementing the loop count - causing your code to skip a row as
you go?"
humm

"Patti" wrote in message
...
Can anyone tell me why this produces Run-time error 13: Type mismatch?

Thanks in advance.

----------

Option Explicit
Private Sub testloop()

Dim lstrow As Long
Dim i As Long
Dim agtname As String

lstrow = Range("a" & Rows.Count).End(xlUp).Rows
For i = 2 To lstrow
agtname = Range("a" & i).Value ' *** also tried .Text & still got

error
MsgBox "Current Name is " & agtname
i = i + 1
Next i
End Sub




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

Thanks Nigel - you were right of course. And good catch JMay - it was not
my intention to skip a row (just learning how to walk through a range!)

Regards,

Patti





"JMay" wrote in message news:aHjuc.2915$Tw.234@lakeread06...
In addition to Nigels comment are you sure you need the line i = i

+
1
as it is "incrementing the loop count - causing your code to skip a row as
you go?"
humm

"Patti" wrote in message
...
Can anyone tell me why this produces Run-time error 13: Type mismatch?

Thanks in advance.

----------

Option Explicit
Private Sub testloop()

Dim lstrow As Long
Dim i As Long
Dim agtname As String

lstrow = Range("a" & Rows.Count).End(xlUp).Rows
For i = 2 To lstrow
agtname = Range("a" & i).Value ' *** also tried .Text & still got

error
MsgBox "Current Name is " & agtname
i = i + 1
Next i
End Sub






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
Type mismatch... George[_4_] Excel Discussion (Misc queries) 7 December 19th 07 12:20 PM
Type mismatch Stuart[_5_] Excel Programming 4 February 19th 04 07:54 PM
Type Mismatch Edgar[_3_] Excel Programming 4 February 13th 04 03:55 PM
Type mismatch Steve Garman Excel Programming 0 February 5th 04 07:39 AM
Type Mismatch Phil Hageman[_3_] Excel Programming 2 January 9th 04 06:11 PM


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