Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-Time Error 13: Type mismatch

Status
Not open for further replies.

Ryan123123

Technical User
Jul 31, 2009
2
CH
Hi all,
I've put together some code that basically will read in some data from a ssheet, perform some operations on it and dump it back out again on the ssheet. So far, I've just coded the basic outline (i.e., not the operations that will be performed) just to check that it'll work....however, I'm getting an error and can't see where it's coming from. I've copied the code below and would really appreciate some help,
Many thanks in advance!



Option Explicit

Sub RunCalc()
Dim DManip As DataManipulation
Dim Data() As Variant, LOB_Num As Double, LOB As Variant


With Application

'Import data from worksheet
Data = .Range("A2:F996")
LOB_Num = .Range("A1")

'Instantiate a new DataManipulation object
Set DManip = New DataManipulation

'Set properties and execute calculations
With DManip
.Data = Data
.Calculate (LOB_Num)
LOB = .LOB
End With

'Dump results into worksheet
'This is where the error comes up!!
.Range("H2:FQ7") = LOB

End With

'Clean up
Set DManip = Nothing

End Sub




Option Explicit
Option Base 1

Private Prems_() As Double, Claims_() As Double, Data_() As Variant
Private Error As Variant, LOB_() As Double


Sub Calculate(LOB_Num As Double)

Dim TotCols As Long, Rows As Long, TotRows As Long
Dim i As Long, j As Long, k As Long, n As Long
Dim tmp_() As Double, Y As Double

'Set error handling
On Error GoTo EndProc

'Set variable number constants
TotCols = UBound(Data_, 2) 'Total no. of columns in dataset
TotRows = UBound(Data_, 1) 'Total no. of rows in dataset
Rows = TotCols 'Total no. of rows per LOB


'In final version should catch any errors in the data here, i.e. _
if data hasn't been exported properly from Axis etc.


'Rearrange the Data
For i = 1 To LOB_Num
n = Rows * (i - 1)
For j = 1 To Rows
k = n + j
Y = Data_(k, 1)
tmp_(j, i) = Y
Next j
Next i

LOB_ = tmp_

'Exit method, no error detected
'Exit Sub

'Exit method, error detected
EndProc:
Error = "Unhandled exception in DataManipulation.Calculate."
End Sub


Static Property Let Data(ip): Data_ = ip: End Property
Static Property Get LOB(): LOB = LOB_: End Property
 
Do you initialise tmp_ (LOB_num=0)?
I get this error after:
Code:
Dim d() As Double, v As Variant
v = d
Application.Range("A1:B1") = v[code]

combo
 
LOB_Num would be a variable read from the ssheet, so don't think it would be this...anyone else any ideas??!
 

Which line do you have this error on?

Either comment out error handling, or go to:
Tools - Options... - General tab - in Error Trapping frame select "Break on All Errors"

Have fun.

---- Andy
 
You've commented out the 'exit sub' before your error is set. As it stands, the last line which sets the Error variable will run even if there is no error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top