Ryan123123
Technical User
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
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