Code execution jumping out of IF statement for unknown reason

pizzaboy

Board Regular
Joined
Mar 23, 2015
Messages
56
Office Version
  1. 2019
Platform
  1. Windows
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...

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)
call, resumes at
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)
, 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):
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:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,224,749
Messages
6,180,731
Members
452,995
Latest member
isldboy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top