So, I'm updating an Excel table with data from another Excel table.
I'm populating the information via a custom class "cls_Record_Title" (no validation - just public properties to collect the data).
Theres no problem with that, all data is correctly collected. The "record" is then passed into a function call of another class (representing the Excel table I want to update - uses code to simulate an inherited class), this obviously makes it a little more difficult to debug...
Anyway...
The code execuation after the
call, resumes at
!?!??
All other code within that first IF statement is skipped?
The function call does return the correct value. When the function call is made the second time
, the remainder of that IF statement runs as expected...
As this code is inside a class, when an error occurs, VBA usually jumps the Library or wherever the first call was made outside of any classes - this isn't happening and the function appears to be working as expected.
Its a bit difficult to debug because Adding the key field of that single row, refreshes quite a lot of formulas inside of the Excel table so stepping through the code just looks like calls to really random functions.
The AddRow() function (my table class populates all the required parameters correctly):
Is there any reason at all why the code execution would jump out of an IF statement and continue elsewhere in the same procedure without EXIT or ON ERROR RESUME calls (I have a lot of INDEX/MATCH calls!).
Any help would be greatly appreciated.
Thanks.
I'm populating the information via a custom class "cls_Record_Title" (no validation - just public properties to collect the data).
Theres no problem with that, all data is correctly collected. The "record" is then passed into a function call of another class (representing the Excel table I want to update - uses code to simulate an inherited class), this obviously makes it a little more difficult to debug...
Anyway...
Code:
Public Sub UpdateRecord(pRecord As cls_Record_Title, bExcludeSort As Boolean)
Dim row As Long
With ActiveWorkbook.Worksheets(Table.WS).ListObjects(Table.TB)
'SERIES
If (pRecord.SeriesRow < 1) Then
[LIST]
[*] row = AddRow(pRecord.Series_IMDB)
[/LIST]
Call Table.Update_NewValue(row, COL_VERSION_IMDB, pRecord.Series_IMDB)
Call Table.Update_NewValue(row, COL_SERIES, pRecord.Series_Name)
Call Table.Update_NewValue(row, COL_GROUP, pRecord.Group)
Call Table.Update_NewValue(row, COL_VERSION_PREFIX, pRecord.Version_Prefix)
Call Table.Update_NewValue(row, COL_VERSION_SUFFIX, pRecord.Version_Suffix)
'LIBRARY
Call Table.Update_NewValue(row, COL_CATEGORY, pRecord.Category)
Call Table.Update_NewValue(row, COL_GENRE, pRecord.Genre)
Call Table.Update_NewValue(row, COL_TYPE, pRecord.Genre_Type)
Call Table.Update_NewValue(row, COL_AUDIENCE, pRecord.Audience)
Call Table.Update_NewValue(row, COL_LANGUAGE, pRecord.Language)
Call Table.Update_NewValue(row, COL_ERA, pRecord.Era)
'COLLECTION
Call Table.Update_NewValue(row, COL_COLLECTION, pRecord.Collection)
End If
[LIST]
[*] If (pRecord.UpdatesRow > 0) Then
[/LIST]
Else
row = pRecord.TitlesRow
If (row = 0) Then
[LIST]
[*] row = AddRow(pRecord.IMDB)
[/LIST]
...
End If
The code execuation after the
Code:
row = AddRow(pRecord.Series_IMDB)
Code:
If (pRecord.UpdatesRow > 0) Then
All other code within that first IF statement is skipped?
The function call does return the correct value. When the function call is made the second time
Code:
row = AddRow(pRecord.IMDB)
As this code is inside a class, when an error occurs, VBA usually jumps the Library or wherever the first call was made outside of any classes - this isn't happening and the function appears to be working as expected.
Its a bit difficult to debug because Adding the key field of that single row, refreshes quite a lot of formulas inside of the Excel table so stepping through the code just looks like calls to really random functions.
The AddRow() function (my table class populates all the required parameters correctly):
Code:
Public Function AddRow(WS As String, TB As String, _
pCol As String, pValue, _
Optional pClear_Row As Long) As Long
Dim row As Long
With ActiveWorkbook.Worksheets(WS)
.Select
With .ListObjects(TB)
row = .HeaderRowRange.row + .ListRows.Count + 1
If ((pClear_Row > 0) And (row > pClear_Row)) Then
Rows(row + 2).Insert
End If
Cells(row, .ListColumns(pCol).Range.Column).value = pValue
row = row - .HeaderRowRange.row
End With
End With
DoEvents
AddRow = row
End Function
Is there any reason at all why the code execution would jump out of an IF statement and continue elsewhere in the same procedure without EXIT or ON ERROR RESUME calls (I have a lot of INDEX/MATCH calls!).
Any help would be greatly appreciated.
Thanks.
Last edited: