I have the following function in the class module vehrows
Private Function extractOrginalSourceVehNum() As String
Dim impFP_searchRng As Range: Set impFP_searchRng = tableSheet.Range("C1:C" & lastRowOfTableSheet)
'It's possible for 2 different car models to have same SourceVeh ID
'Search for 1st impFilePrefix row, then search for 1st occurence of sourceVeh and extract original vehNum
Dim impFilePrefix_Cell As Range: Set impFilePrefix_Cell = impFP_searchRng.Find(What:=impFilePrefixStr, lookat:=xlWhole, After:=impFP_searchRng(impFP_searchRng.Count))
'Allows us to start searching at the first instance where impfilePrefix was obtained.
Dim sVeh_searchRng As Range: Set sVeh_searchRng = tableSheet.Range(Cells(impFilePrefix_Cell.Row, 1), Cells(lastRowOfTableSheet, 1)) '1 is columnA
Dim sourceVehCell As Range: Set sourceVehCell = sVeh_searchRng.Find(What:=sourceVeh, lookat:=xlWhole)
'Dim result As String: result = sourceVehCell.Offset(, 1).Value
extractOrginalSourceVehNum = sourceVehCell.Offset(, 1).Value
End Function
It its called from the alternate constructor of the class
Public Sub InitializeAttributes(...)
sourceVehCell_vehNum = extractOrginalSourceVehNum 'Original vehNum of derived SourceVeh File, must be placed after 'lastRowOfTableSheet ='
End Sub
I get error 91. I then go ahead and place set in front of the statement
Set sourceVehCell_vehNum= sourceVehCell.Offset(, 1).Value
It then states Object Required for sourceVehCell_vehNum.
I had it combined with another function, the problem did not occur, i.e.
'Type B' selected in TableSheet, will trigger this function
'This is updated, because a veh file may have a suffix totally different from "VehNum"
Private Function updateSourceVeh()
Dim lastRowOfTableSheet As Integer
lastRowOfTableSheet = tableSheet.Range("A" & Rows.Count).End(xlUp).Row
Dim impFP_searchRng As Range: Set impFP_searchRng = tableSheet.Range("C1:C" & lastRowOfTableSheet)
'It's possible for 2 different car models to have same SourceVeh ID
'Search for 1st impFilePrefix row, then search for 1st occurence of sourceVeh and extract original vehNum
Dim impFilePrefix_Cell As Range: Set impFilePrefix_Cell = impFP_searchRng.Find(What:=impFilePrefixStr, lookat:=xlWhole, After:=impFP_searchRng(impFP_searchRng.Count))
'If impFilePrefix for each car model is only specified once in the corresponding row, be sure to make sure loop doesn't exceed last row, if necessary
'Allows us to start searching at the first instance where impfilePrefix was obtained.
Dim sVeh_searchRng As Range: Set sVeh_searchRng = tableSheet.Range(Cells(impFilePrefix_Cell.Row, 1), Cells(lastRowOfTableSheet, 1)) '1 is columnA
Dim sourceVehCell As Range: Set sourceVehCell = sVeh_searchRng.Find(What:=sourceVeh, lookat:=xlWhole)
'tableSheet.Range("K2").Value = sourceVehCell.Value
Dim sourceVehCell_vehNum As String: sourceVehCell_vehNum = sourceVehCell.Offset(, 1).Value 'Original veh num of derived SourceVeh
'If vehNum matches orgiVehNum, don't run
If sourceVehCell_vehNum <> vehNum Then
If Len(sourceVehCell_vehNum) <> Len(vehNum) Then
'VehNum was derived from sourVeh, right... right?
sourceVehCell_vehNum = enlargeOrigVehNum(sourceVeh, sourceVehCell_vehNum, vehNum)
End If
'Replace origVehNum in sourceVeh with vehNum, by extracting values left of, and the appending it.
Dim tempSourceVeh As String: tempSourceVeh = truncateSourceVeh(sourceVeh, sourceVehCell_vehNum) + vehNum
sourceVeh = tempSourceVeh + Right(sourceVeh, Len(sourceVeh) - Len(tempSourceVeh))
End If
End Function
Bookmarks