+ Reply to Thread
Results 1 to 2 of 2

Problems with Cells.Find. Object/Block variable not set

  1. #1
    Registered User
    Join Date
    06-26-2007
    Posts
    6

    Problems with Cells.Find. Object/Block variable not set

    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

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    please read forum rules below and then wrap your code.

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1