Excel Crashes after VBA adds rows to table

kscarlett5683

New Member
Joined
Feb 29, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi, I have searched everywhere and cannot find a good answer to my problem. I am writing a VBA macro that, amongst other things, gets data from another workbook and then adds rows to the primary workbook's table. I have isolated the problem to literally just expanding rows to a table -- my code works fine without this step. Additionally, just running the expanding rows code crashes Excel. The script will add the rows, but as soon as you save or leave Excel, it shuts down and restarts automatically. My code is below. Does anyone have any idea how to fix this? I am using Windows 10 and Office 365. Excel 64 bit. Thank you

counterADR = 12
If counterADR > 0 Then
'resize the table instead of adding rows. Adding rows crashes the script.
tblTracker.Resize tblTracker.range.Resize(tblTracker.range.Rows.count + counterADR)
End If
startingRow = tblTracker.range.Rows.count - counterADR


P.S. The workbook I am using is quite small.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
It runs fine for me without crashing Excel. Also, adding a ListRow as apposed to resizing shouldn't be a problem either...

VBA Code:
'get table from sheet1
Dim tblTracker As ListObject
Set tblTracker = ThisWorkbook.Worksheets("Sheet1").ListObjects(1)

'add a listrow to the end of the table
Dim currentListRow As ListRow
Set currentListRow = tblTracker.ListRows.Add

'enter a value into the first cell of the new listrow
currentListRow.Range(1, 1).Value = "x"

It might help if you posted the complete code.
 
Upvote 0
It runs fine for me without crashing Excel. Also, adding a ListRow as apposed to resizing shouldn't be a problem either...

VBA Code:
'get table from sheet1
Dim tblTracker As ListObject
Set tblTracker = ThisWorkbook.Worksheets("Sheet1").ListObjects(1)

'add a listrow to the end of the table
Dim currentListRow As ListRow
Set currentListRow = tblTracker.ListRows.Add

'enter a value into the first cell of the new listrow
currentListRow.Range(1, 1).Value = "x"

It might help if you posted the complete code.
Of course it does, that's the story of my life! LMAO The reason I didn't post the whole thing was because I literally isolated just that code, ran it, and Excel crashed. It's very strange.

The other reason is because that is A LOT of code! I have to take a report, modify to get rid of extra rows, and then turn the whole thing into a table. Once all that re-formatting is done, I do a compare. I delete rows in the primary workbook with data that doesn't exist in the report. I then add what isn't already in the primary workbook (which brings me to the problem code).

But, in looking at your code, it occurs to me I can be more efficient by using a loop and adding a new row that way -- prior to doing this I was getting out of memory issues A LOT, so I re-wrote from scratch trying to optimize. Let me try this and see what happens.
 
Upvote 0
Sound good ... :cool:
So, that didn't work either. It literally crashed Excel. This is frustrating. This is the code I used (all variables and objects are properly set, so that is not the issue):

Dim newRow As listRow
For j = LBound(arrADRNotFound) To UBound(arrADRNotFound)
If Not IsEmpty(arrADRNotFound(j)) Then
Debug.Print "The Tracker ID is this: " & arrADRNotFound(j)
Set newRow = tblTracker.ListRows.Add
newRow.Range(1, 2).Value = arrADRNotFound(j) 'adds a new row with the assessment id
End If
Next j
 
Upvote 0
I think I know what the issue is. I started with a fresh workbook and copied the table over to it. I then used that fresh workbook to run my code - and everything worked just fine with no crashing. There is a corruption somewhere. I guess I'll have to rebuild this from scratch and discard the old file.
 
Upvote 0
You could try to repair your workbook. So instead of clicking on Open when opening your workbook, click on the drop down arrow and select Open and Repair.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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