PDA

View Full Version : Run Time Error 13 Message, very strange !



vodkasoda
03-11-2009, 07:55 AM
I have attached my Spreadsheet, this is very odd, or I have done something very stupid !!!

I have 2 definitions as follows ...

Public MyUniqueNo As Integer
Public MyNoOfTeams As Integer

I have 2 statements as follows ...

MyUniqueNo = Sheets("Players").Range("A65536").End(xlUp).Value
MyNoOfTeams = Sheets("Teams").Range("A65536").End(xlUp).Value

I am getting an error on the 2nd line, "Run-time error '13': Type mismatch" ... I can switch the variables and it always works unless I am using the "Teams" sheet, whereas I always get this error ... why :think: ?!?!?

Many apologies if this is embarrasingly stupid, but I just can't see it !!!

nst1107
03-11-2009, 08:07 AM
The last cell in column A of sheet "Teams" has a string value. Your variable is an integer type. Switch it to a string or variant.

vodkasoda
03-11-2009, 12:27 PM
The last cell in column A of sheet "Teams" has a string value. Your variable is an integer type. Switch it to a string or variant.
Thank you Nate, I knew it was going to be something really stupid !!!

As it happens, my actual problem & resolution was slightly different, as it was (is) an integer that I need (the last populated Row in the Column).

What I did was change the line

MyNoOfTeams = Sheets("Teams").Range("A65536").End(xlUp).Value
to

MyNoOfTeams = Sheets("Teams").Range("A65536").End(xlUp).Row
but it was your comment that made me realise what a fool I was being ... couldn't see the wood for the trees, as they say !!!

:beerchug:

Cheers ...

nst1107
03-11-2009, 12:58 PM
Glad it helped. Be careful when setting an integer variable to a row to make sure that the row will never exceed 32,767. Otherwise you will get an error. If you need rows beyond that, use a long variable instead.

Bob Phillips
03-11-2009, 01:08 PM
In fact, never use Integre as a data type (or Single for that matter). The OS will convert to a long to do its work, and convert the result back to an Integere. Pointless overhead.