grantlocke
New Member
- Joined
- May 27, 2014
- Messages
- 4
Hi, I would be extremely grateful for your help. I am trying to get match dates in two different arrays, both declared as variants and regardless of whether or not the dates actually match I get an (Error 2042). I have reproduced the code below. How the code works:tsdata() = loads an array of 3860 x 4 (first column are daily dates stored in date format)tsubdata()= a subset of tsdata 758x4 (first column are daily dates, rest are % changes)mDate() = 185 (a series of month end dates)Once tsubdata is loaded, the reference tsubdata(758,1) should be matched to mDate() the entire range of 185 dates, if the result is numeric, i.e. a positive integer then the code will carry on and call another macro, if not, it should just carry on until it does. In other words, I am creating an array and the last reference in column 1 should match a month end. Would be very grateful for your helpThanksGrantSub tsCalculator() 'time series calculatorDim tsData() As VariantDim tsubData() As VariantDim Mdate() As VariantDim a As IntegerDim b As IntegerDim c As IntegerDim d As IntegerDim tsTotal As IntegerDim tsAdvance As Integer 'number of periods between the initial period and end of time seriesDim tsheight As Integer'Redimension arrayReDim tsData(1 To 3861, 1 To 4)ReDim Mdate(1 To 185)ReDim tsubData(1 To 758, 1 To 4)'Load data into arraysData = Range("pData")Mdate = Range("mdates") 'Dimensionstsheight = 758 ' number of days in three yearstsTotal = 3861 ' Total number of rows in data set - daily datatsAdvance = tsTotal - tsheightc = 1'Create calculated timeseries based on portfolio weightsFor d = 1 To tsAdvance 'Create a sub array from tsData = fixed height of 3 years - 758 data points For a = c To tsheight For e = 1 To 758 For b = 1 To 4 tsubData(e, b) = tsData(a, b) Next b Next e, a If IsNumeric(application.match(tsubData(e-1,1),mdate,0)) Then 'THIS IS WHERE THE PROBLEM IS I GET A 2042 EVEN IF THE DATES SHOULD MATCH'DosomethingElseGoto Line1End IfLine1: tsheight = tsheight + 1c = c + 1End sub
Last edited: