Hi folks,
So im just learning VBA and i thought i could use it to replace one of my more complicated formulas.
So basically what this does is calculates the mark to market of various contracts depending on type, pipe, and date.
It ran fine for a while and all of a sudden i'm getting gaps, funny thing is when i renamed the Function, it worked, then stopped again.
HELP WHAT AM I SCREWING UP?
So im just learning VBA and i thought i could use it to replace one of my more complicated formulas.
So basically what this does is calculates the mark to market of various contracts depending on type, pipe, and date.
It ran fine for a while and all of a sudden i'm getting gaps, funny thing is when i renamed the Function, it worked, then stopped again.
HELP WHAT AM I SCREWING UP?
Code:
Dim k_type As String
Dim pipe As String
Dim Fixed As Currency
Dim Adder As Currency
Dim adder_per As Integer
Dim cap As Currency
Dim floor As Currency
Dim part_per As Integer
Dim Volume As Integer
Dim date_val As Date
Dim capped_k As Integer
Dim capped_v As Integer
Dim Target_k As Integer
Function Mark(k_type, pipe, Fixed, Adder, adder_per, cap, floor, part_per, Volume, date_val)
Application.Volatile
index_val = WorksheetFunction.Index(Range("monthly_index"), WorksheetFunction.Match(pipe, Range("indexes_names"), 0), WorksheetFunction.Match(date_val, Range("Index_date"), 0))
Target_k = (((adder_per * 0.001) * index_val) + Adder) * Volume
fixed_k = (Fixed - index_val) * Volume
capped_v = (cap - (((adder_per * 0.001) * index_val) + Adder) - index_val)
If capped_v > 0 Then
capped_k = 0
Else
capped_k = capped_v * Volume
End If
floor_v = (floor - (((adder_per * 0.001) * index_val) + Adder) - index_val)
If floor_v < 0 Then
Floor_k = 0
Else
Floor_k = floor_v * Volume
End If
part_k = part_per * Target_k + (1 - part_per) * fixed_k
If k_type = "TARGET" Then
Mark = Target_k
Else
If k_type = "FIXED" Then
Mark = fixed_k
Else
If k_type = "COLLARED" Then
Mark = Floor_k + capped_k + Target_k
Else
If k_type = "PARTNER" Then
Mark = part_k
Else
If k_type = "CAPPED" Then
Mark = capped_k
Else
If k_type = "CAPPED GTD SAVE" Then
Mark = Target_k
Else
If k_type = "FIXED PRICE VOL REQ" Then
Mark = fixed_k
Else
If k_type = "GUARANTEED" Then
Mark = Target_k
Else
If k_type = "MHA ES" Then
Mark = fixed_k + (capped_k * 0.5) + (floored_k * 0.5)
Else
If k_type = "MHA COLL" Then
Mark = Floor_k + capped_k + Target_k
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Function