Excel VBA Frustrating Run-time error '13' Type mismatch

shastamccloud

New Member
Joined
Dec 6, 2010
Messages
4
Hi everyone,

I'm getting frustrated as heck trying to resolve an error 13 in my Macro Code in my Excel 2007 spreadsheet. I've read all about this error and understand that it's sometimes caused by mixing strings into math equations.

The code is: (the error is the second line)

If Executive.Cells(4, 14) > 0 Then
Retirement.Cells(17, 7) = Retirement.Cells(17,6) / Executive.Cells(4, 14)

The debugger says that the value of Retirement.Cells(17,6) is 76.692, and the value of Executive.Cells(4,14) is "". At first, I thought this error was caused by that Null value in (4,14), but this code works successfully in other spreadsheets with these values.

Also, i guess I have a second question: If that value is Null, then how do that trigger this loop? I always assumes that Null was not considered greater than zero.

BACKGROUND: this spreadsheet was produced as a report by an ASPX server. A spreadsheet is put on the server as a blank template, then the server fills it with data and downloads to the user.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi

Firstly I think you should explicitly qualify the property you want to work with.
Secondly are you sure that the cell Is Null, and that it isn't being considered a string because of the import process?

Perhaps:
Code:
If Len(Executive.Cells(4, 14)[COLOR=Red].Text[/COLOR]) > 0 Then 'make sure it isn't empty
    Retirement.Cells(17, 7)[COLOR=Red].Value[/COLOR] = Retirement.Cells(17, 6)[COLOR=Red].Value[/COLOR] / Executive.Cells(4, 14)[COLOR=Red].Value[/COLOR]
End If

Or, consider using CDbl to coerce the value in Cells(4,14) to a double.
 
Upvote 0
Jon, thank you so much for your reply; that solved the issue.

You are exactly right: I'm not sure that a cell is null, and not considered a string by the import process. After all the time I've spent on the spreadsheet, I'm fairly certain there's strings in there causing confusion.

I have not yet tried the CDbl option to see if that works as well, but that's next on my list.

thank you ,
 
Upvote 0
hi,

I am responding to this thread because i seem to be getting a similar problem in my code.Please help on the highlighted line
Code:
Dim c As Range
[B]SQL1 = ThisWorkbook.Worksheets("Index").Range("Environ4")[/B]
For Each c In ThisWorkbook.Worksheets("Index").Range("Environ4")
    c.Offset(, 2).Value = c.Value
Next c

End
 
Upvote 0
Tiffany, sorry to hear you're having that problem.

Your code doesn't contain the Variable definition for SQL1. It looks like you're using SQL1 as a range. If you defined SQL1 as a different data type, that might cause the error.

You're getting that error because the computer expected a certain type of data, and instead it got a different type.
 
Upvote 0
Hello All,
I am new in VBA. I would like to transfer multiple *.txt files in my excel file. I write it down a following code but i am getting run-time error 13. I could not able to solve it. Could you please help me to sort out this problem:
Sub Text_ImportAllFiles()
For rep = 4 To 7


Dim file_name As String
Dim row_mumber As String
Dim output_sheet As String

file_name = Sheets("Admin").Range("B" & rep).Value
output_sheet = Sheets("Admin").Range("C" & rep).Value
row_number = Sheets("Admin").Range("D" & rep).Value

With Sheets(output_sheet).QueryTables.Add(Connection:="TEXT" + file_name, Destination:=Sheets(output_sheet).Range("$A$" + row_number))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = True
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With

Dim wb_connection As WorkbookConnection
For Each wb_connection In ActiveWorkbook.Connections
If InStr(file_name, wb_connection.Name) > 0 Then
wb_connection.Delete
End If
Next wb_connection
Next rep
MsgBox "Done"
End Sub

Thanks a lot in advance...

Anubhav





 
Upvote 0
I have the same error in my file.

The error is in this code:
"
Dim i, k As Long
i = 0
k = 0
While Cells(i + 1, 1) <> ""
i = i + 1
If i = 1 Then
k = k + 1
Sheets("Final").Cells(k, 1) = Cells(i, 1)
Sheets("Final").Cells(k, 2) = Cells(i, 2)
Sheets("Final").Cells(k, 3) = Cells(i, 3)
Sheets("Final").Cells(k, 4) = Cells(i, 4)
Sheets("Final").Cells(k, 5) = Cells(i, 5)
Sheets("Final").Cells(k, 6) = Cells(i, 6)
Sheets("Final").Cells(k, 7) = Cells(i, 7)
Sheets("Final").Cells(k, 8) = Cells(i, 8)
Sheets("Final").Cells(k, 9) = Cells(i, 9)
ElseIf Cells(i, 11) <> "Não" And (Cells(i, 12) = "FUTURA" Or Cells(i, 12) = "CORRENTE" Or Cells(i, 12) = "PERMANENTE") Then
k = k + 1
Sheets("Final").Cells(k, 1) = Cells(i, 1)
Sheets("Final").Cells(k, 2) = Cells(i, 2)
Sheets("Final").Cells(k, 3) = Cells(i, 3)
Sheets("Final").Cells(k, 4) = Cells(i, 4)
Sheets("Final").Cells(k, 5) = Cells(i, 5)
Sheets("Final").Cells(k, 6) = Cells(i, 6)
If Sheets("Extract").Cells(i, 13) = "" Then
Else
Sheets("Final").Cells(k, 7) = Cells(i, 13)
End If
Sheets("Final").Cells(k, 8) = Cells(i, 8)
Sheets("Final").Cells(k, 9) = Cells(i, 9)
End If
Wend
"

The line where i have error is marked with red bold.

Anyone can help me?

Thank's
 
Upvote 0

Forum statistics

Threads
1,215,350
Messages
6,124,431
Members
449,158
Latest member
burk0007

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