2013 Version Crashes on VBA Table Entry

leryt

New Member
Joined
May 11, 2019
Messages
4
The VBA code works well in excel 2010. My computer was updated with a 2013 and now the code always crashes in one area. I have received out of range errors to catastrophic errors. I am uncertain of how to fix it as I have attempted every other approach.

Error Details
So I have several tables set up in my excel sheets. I am trying to grab a unique number and have it paste to a table at the end. The table is filled with formulas and rely on the unique number to move through the process. The problem arises when I set the variable to be applied to the table.

I have Dimmed Initacct as string:
Dim initacct As String

When I walk through the code it initacct is defined appropriately and I can see the ID number.
When removing the last digit for my pinitacct string it also works.
Also if Dptlist.Range("$A$2").Value = "" it will also pass and apply initacct without any errors.
It is on my else statement that this crashes on the code: Dptlist.Range("A" & lrow) = initacc

Please help. Original code below.

Code:
Private Sub Userform_Initialize()
'Clear
'Extract
'NewLine
 
'Reviewed and cleaned
'pending error handle
 
Dim wb As Workbook
Dim crit, Datasrc, Dptlist, Datastat, ptlist As Worksheet
Dim SourceDept, deptlook, tbltwo, tblone, plist, StatY, PtA, DepA As Range
Dim Dept, initacct, pinitacct As String
Dim i, c, dI, pI, j As Integer
Dim lrow, prow As Long
Dim TblTwoOb As ListObject
 
'Workbook
Set wb = ThisWorkbook
    wb.Activate

'Sheets
Set crit = Sheet8
Set Datasrc = Sheet1
Set Dptlist = Sheet5
Set Datastat = Sheet6
Set ptlist = Sheet2
'Ranges
Set SourceDept = Datasrc.Range("SourceD")
Set tbltwo = Dptlist.Range("Table2[#All]")
Set tblone = ptlist.Range("Table1[#All]")
Set PtA = ptlist.Range("$A$2")
Set DepA = Dptlist.Range("$A$2")
'Objects
Set TblTwoOb = Dptlist.ListObjects("Table2")
'String
Dept = crit.Range("$A$2").Value
 
Application.ScreenUpdating = False

'On Error Resume Next
wb.Activate
Me.Label64 = Dept
 
'extract new accounts from list
For Each deptlook In SourceDept
    If deptlook.Value = Dept Then
        lrow = Dptlist.Cells(Rows.Count, 1).End(xlUp).Row + 1
        prow = ptlist.Cells(Rows.Count, 1).End(xlUp).Row + 1
            initacct = deptlook.Offset(0, -2).Value
            pinitacct = Left(initacct, Len(initacct) - 1)
                If Dptlist.Range("$A$2").Value = "" Then
                    Dptlist.Range("$A$2").NumberFormat = "@"
                    Dptlist.Range("$A$2") = initacct
                        Else
                            Dptlist.Range("A" & lrow).NumberFormat = "@"
                            'ERROR HAPPENS BELOW but not on pinitacct
                            Dptlist.Range("A" & lrow) = initacct
                End If
                If ptlist.Range("A2").Value = "" Then
                    ptlist.Range("A2").NumberFormat = "@"
                    ptlist.Range("A2") = pinitacct
                        Else
                            ptlist.Range("A" & prow).NumberFormat = "@"
                            ptlist.Range("A" & prow) = pinitacct
                End If
    End If
Next deptlook
 
'MORE CODE BELOW
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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