Type Mismatch -- Error 13 in VBA

dmacdougall

New Member
Joined
Oct 18, 2005
Messages
43
Where I can find info on correcting the debugger error "Type Mismatch"?

The Excel help for this subject is rather general, and I'm not familiar enough with VBA to be sure which of my variables is causing this problem...

Also, why can I just get rid of this by using Variant-type variables? Arrrgh! :) dm
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
If you post your code it would be easier to diagnose.

The type mismatch is just that....you have a variable assigned that does not meet the expected variable format. Like you have text instead of an integer or something. Although this code be in the worksheet text that it is reading as well...

It is always better to specifiy your declared variable as the code works more efficiently. If you post your code and indicate the line in question, should be real easy to spot.
 
Upvote 0
Using Variants is just not good coding.

You can step through your code by getting into the VB Editor and clicking

Debug | step into

each time you hit F8, it'll execute a line of code and you can see the error line.
 
Upvote 0
Code is below -- I suspect the variable countyStr is the problem -- I changed it from a String type to Variant, but that did not solve the problem.

The data on the worksheet is a specific name of a county, formatted in the "Text" format.

Perhaps I need a Boolean-formatted variable to hold the data from the worksheet?

I will also double-check to make sure I'm not grabbing the data from the wrong cell, but I doubt that's the problem...

sigh... I wish I was a genius like Mr. Excel! :) dm





Private Sub CountTotalLosses()

Dim countyStr As Variant
Dim ctCounterInt As Integer
Dim tlCounterInt As Integer


ctCounterInt = 3
tlCounterInt = 0

Do While ctCounterInt < 100

countyStr = Sheets(Sheet1).Cells("B", ctCounterInt).Value

If Sheets(Sheet9).Cells("G", ctCounterInt).Value = countyStr And _
Sheets(Sheet9).Cells("N", ctCounterInt).Value = "True" Then

tlCounterInt = tlCounterInt + 1

Else

tlCounterInt = tlCounterInt + 0

ctCounterInt = ctCounterInt + 1

End If

Loop


End Sub
 
Upvote 0
John -- tell me about it! I know almost nothing about programming, but when I saw how much space is allotted for a Variant, I hated it right from the beginning. But, I thought that perhaps it might be able to hold more type of data than the other variable types.

I will try your suggestion for running throught the code one line at a time -- I can seem to figure out where the parser is having a problem... thanks! :) dm
 
Upvote 0
Try taking out the

.value

from the various lines in your statement
that should do it.

Code:
 countyStr = Sheets(Sheet1).Cells("B", ctCounterInt)

If Sheets(Sheet9).Cells("G", ctCounterInt) = countyStr And _
Sheets(Sheet9).Cells("N", ctCounterInt) = "True" Then 
[/code
 
Upvote 0
Gibbs --

thank you!!! I'd forgotten that the .Value does try and pull the actual value, rather than just passing the data unchanged.

I will try and remove that and I'll post again if that does not work...
 
Upvote 0
OK, sorry to report that removing the ".Value" did not resolve the issue.

I guess the real question is whether this line is written correctly -- will this line of code insert the value in cell A3 in the first Sheet of the workbook in to the variable countyStr, if the variable ctCounterInt is equal to 3?

countyStr = Sheets(Sheet1).Cells("A", ctCounterInt)

Or am I just hopeless? :oops: :(
 
Upvote 0
countyStr = Sheets(Sheet1).Cells("A", ctCounterInt)

should be

countyStr = Sheets("Sheet1").Cells(ctCounterInt,"A")
 
Upvote 0

Forum statistics

Threads
1,214,829
Messages
6,121,827
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top