When you declared the variables Relation and Account as ranges with:
Dim Relation As Range
Dim Account As Range
You were saying that you were going to use Relation and Account to "refer to" or "point to" ranges of cells in a worksheet.
Once you declare your intentions (i.e., DIM), they must be made to actually point to/refer to some cells. This is done with the SET Statement.
Dim only grabs some empty/unused available memory area and reserves (tags) it Relation or Account (in this case). You must point them to a range of cells:
Set Relation = some cell/range of cells.
Set Account = some other cell/range of cells
Once you have pointed them to the cells you can then use
With Relation
.Value = ReferenceDataRange(i, 1)
End With
Account.Value = ReferenceDataRange(i, 2)
There is no Set for Relation and Account so the With Relation translates to With NOWHERE, put the data from my array... which results in the Object or With block error.
But!
Notice that, in your code, you are only using Relation and Account to hold data values from an array. They never are used to refer to ranges of cells; therefore, they cannot be declared as Range variables. I don't know what kind of data you are working with (no workbook to look at ) so I'm guessing (again) that it is string or maybe integer.
Dim Relation as ? (variant, string, long?)
Dim Account as ...
Relation = ReferenceDataRange(i, 1)
Account = ReferenceDataRange(i, 2)
I've noticed that you want to assign an account number after Relation is found by the search code, but there is no code to actually put that back in a cell in the workbook. So it looks like you still need code to put the account in some cell in the same row as that where the relation is found (???)
Bookmarks