VBA Macro breaks @ >30,000 rows

log0r

New Member
Joined
Feb 11, 2016
Messages
27
Hi all,

I've been running a VBA macro dealing with 2 xls sheets, one with approx 15,000 rows, and one with now over 30,000 rows. Somewhere between 30,000 and 30,700 I am now up to, the part of my macro which concatenates the 30,000 row spreadsheet and then pastes into the 15,000 row spreadsheet breaks.

The error I get is "Run-time error '1004': Application-defined or abject-defined error
This is while running "Ar(1).Offset(-1) = Trim(Join(Application.Transpose(Ar), ", "))" in the following piece of VBA:

Code:
Sub ConcatBetweenBlanks()
  Dim Ar As Range
  For Each Ar In Columns("B").SpecialCells(xlConstants).Areas
    If Ar.Count = 1 Then
      Ar(1).Offset(-1) = Ar
    Else
      Ar(1).Offset(-1) = Trim(Join(Application.Transpose(Ar), ", "))
    End If
  Next
  Columns("A").SpecialCells(xlBlanks).EntireRow.Delete
End Sub

After some googling I've found VBA may have a limit at 32,000 rows of data to copy/paste. I'm not convinced this is my issue though as I'm just shy of this number. If this is the issue, I don't understand how exactly I'm likely to be able to work around it - as in the future these rows are only going to increase to somewhere around 60,000.

As always any help or advice would be very much appreciated!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
How much text are you catenating?
 
Upvote 0
Currently the character count for the range to catenate is 263,000 - these comprise the keywords tied back to SKU's in the original 15,000 part number sheet.
 
Upvote 0
A cell can only contain 32767 characters.
 
Upvote 0
Sorry, I can't have been clear, so those 263,000 characters are in 30,000 cells - no cell has more than approx 200 characters. This one really has me stumped sorry (but nothing else has changed apart from the increased cells that I can tell...)
 
Upvote 0
You're catenating a bunch of cells into a single cell. My question is, what's the longest result? More specifically, what's the length of the result when the code fails?
 
Upvote 0
shg, I'd like to offer an example of my "keywords" sheet (now with 30,700 rows - of which there are 8,000 SKU's (col A)).. it is exported in XLS format and contains the keywords but also some data I don't need.

[TABLE="width: 696"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]SKU[/TD]
[TD]Keywords[/TD]
[/TR]
[TR]
[TD]redcap[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]hat - *notes here about hats*[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]cap - *notes here about caps*[/TD]
[/TR]
[TR]
[TD]bluepants[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]trousers - *notes here about trousers*[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]longs[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]leggings[/TD]
[/TR]
[TR]
[TD]redpants[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]trousers[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]longs[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]leggings[/TD]
[/TR]
[TR]
[TD]greenshirt[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]T-Shirt[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]tshirt[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]top - *notes here about tops*[/TD]
[/TR]
[TR]
[TD]blueshirt[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]T-Shirt[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]tshirt[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]top[/TD]
[/TR]
</tbody>[/TABLE]

The macro ignores anything in range B after a space " " as that information is needless for my keywords. and then concatenates it alongside the SKU it's supposed to be with (in column A, above).

Does this help give some more context?
 
Upvote 0
If you put a workbook (that fails) on box.net and post a link, I'll take a look.
 
Upvote 0
So when the code fails, and I run debug... every cell in column B has been trimmed (anything after a space removed), the whole range A:B30721 is selected, showing me the start of the spreadsheet with "Ar(1).Offset(-1) = Trim(Join(Application.Transpose(Ar), ", "))" being highlighted... So not one part of concatenation has begun (which isn't giving me any hint as to which part is too long, apart from the whole of A:B right?

The largest SKU (col A) to concatenate has 113 cells (in col B) with a total of 1263 characters (so 113 keywords comprising 1263 characters... which that particular SKU and it's keywords have been working for years).

I really appreciate your efforts Shg, this one has me stumped.
 
Upvote 0
I ran it on the small sample you posted and it worked fine (aside from that you can have an entry in B1).

Without seeing the problem, I have no suggestion.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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