The error occurs with the line:
matchRow = dataMatrixRng.Cells.Find(what:=datesVector(j, 1), _
SearchDirection:=xlNext, _
After:=dataMatrixRng(11, 1), _
SearchOrder:=xlByRows).Row
datesVector contains a vector of dates, nonempty everywhere.
DataMatrixRng contains a vector of dates aswell...
When i hold the mousebutton over the values in the formula, i get exactly the inputvalues i want.
Sometimes the code works perfectly, but sometimes it just returns errors!
I want the row where the data in datesVector(j,1) matches the one in dataMatrixRng. Below is the complete code
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Match the data to the dates
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim timeSerieSheet As Worksheet
For i = 2 To tempSheet.UsedRange.columns.Count
tempSheetNum = tempSheet.Cells(5, i).Value
tempSheetDatesColumn = tempSheet.Cells(6, i).Value 'which column does the DATES exist
tempSheetColumn = tempSheet.Cells(7, i).Value 'which column does the DATA exist
tempSheetStartRow = tempSheet.Cells(8, i).Value 'which row
tempSheetEndRow = tempSheet.Cells(9, i).Value 'which column
tempSheetStartRow = tempSheet.Cells(8, i).Value 'which row
tempSheetEndRow = tempSheet.Cells(9, i).Value 'which column
'Set the cells where to fetch, and print information
'cells for DATA
Set topCell = ThisWorkbook.Sheets(tempSheetNum).UsedRange.Cells(tempSheetStartRow, tempSheetColumn)
Set bottomCell = ThisWorkbook.Sheets(tempSheetNum).UsedRange.Cells(tempSheetEndRow, tempSheetColumn)
'cells for DATES
Set topDateCell = ThisWorkbook.Sheets(tempSheetNum).UsedRange.Cells(tempSheetStartRow, tempSheetDatesColumn)
Set bottomDateCell = ThisWorkbook.Sheets(tempSheetNum).UsedRange.Cells(tempSheetEndRow, tempSheetDatesColumn)
'RANGES
Set dataVector = ThisWorkbook.Sheets(tempSheetNum).Range(topCell, bottomCell)
Set datesVector = ThisWorkbook.Sheets(tempSheetNum).Range(topDateCell, bottomDateCell)
Dim Counter As Integer
Dim matchRow As Integer
Dim dataMatrixRng As Range
Set dataMatrixRng = dataMatrixSheet.UsedRange
For j = 1 To tempSheetEndRow - tempSheetStartRow + 1
'Find out which row in dataMatrix corresponds to the current date of our timeseries
matchRow = dataMatrixRng.Cells.Find(what:=datesVector(j, 1), _
SearchDirection:=xlNext, _
After:=dataMatrixRng(11, 1), _
SearchOrder:=xlByRows).Row
dataMatrixRng.Cells(matchRow, i).Value2 = dataVector(j, 1) 'Set the date
Next j
Next i
Bookmarks