Run-time error1004 in code when searching through large data set

ijhoeq

Board Regular
Joined
Jun 20, 2018
Messages
61
Hello,

I have a command button in my workbook that runs code which searches through a column of data (each cell in the column is text inputted in the form of a few sentences) and creates a word count on another sheet in the workbook. The code is written so that every time if finds a new word it is added to the new sheet and it counts how many time that word appears in the column. It then sorts the newly created word count table in order from most occurring word to least occurring. This code runs for two different columns ("Failure" column and "Maintenance Action" column).

The code works great until the data set is around 12,000+ cells long. When it is this long I get an error of the following type: "Run-time error '1004': Application-defined or object-defined error." When I click "Debug" it highlights the line "Sheets("Maintenance Action Word Counts").Range("A1").Resize(.Count, 2).Value = Application.Transpose(Array,.keys,.items))" It never has an error on the Failure Word Count which is of the same length as the Maintenance Action Word Count.

Please look at the code below and let me know if you have any suggestion or further questions.

Code:
    'Failure COUNTS CODE
    Dim Ary As Variant, Sp As Variant
    Dim I As Long, j As Long
   
    With Sheets("Word Search")
        Ary = .Range("C2", .Range("C" & Rows.Count).End(xlUp)).Value2
    End With
    With CreateObject("scripting.dictionary")
        For I = 1 To UBound(Ary)
            Sp = Split(Ary(I, 1))
        For j = 0 To UBound(Sp)
            .Item(Sp(j)) = .Item(Sp(j)) + 1
        Next j
        Next I
            Sheets("Failure Word Counts").Range("A1").Resize(.Count, 2).Value = Application.Transpose(Array(.keys, .items))
    End With
    
    'Sort in order from largest to smallest
    LastRow = Worksheets("Failure Word Counts").Range("B" & Rows.Count).End(xlUp).Row
    Worksheets("Failure Word Counts").Range("A1:B" & LastRow).Sort _
    key1:=Worksheets("Failure Word Counts").Range("B:B"), order1:=xlDescending, Header:=xlNo
    
'-----------------------------------------------------------------------------------------------------
    'Maintenance Action COUNTS CODE
    With Sheets("Word Search")
        Ary = .Range("D2", .Range("D" & Rows.Count).End(xlUp)).Value2
    End With
    With CreateObject("scripting.dictionary")
        For I = 1 To UBound(Ary)
            Sp = Split(Ary(I, 1))
        For j = 0 To UBound(Sp)
            .Item(Sp(j)) = .Item(Sp(j)) + 1
        Next j
        Next I
'CLICKING DEBUG HIGHLIGHTS THE FOLLOWING LINE
            Sheets("Maintenance Action Word Counts").Range("A1").Resize(.Count, 2).Value = Application.Transpose(Array(.keys, .items))
    End With
    
    'Sort in order from largest to smallest
    LastRow = Worksheets("Maintenance Action Word Counts").Range("B" & Rows.Count).End(xlUp).Row
    Worksheets("Maintenance Action Word Counts").Range("A1:B" & LastRow).Sort _
    key1:=Worksheets("Maintenance Action Word Counts").Range("B:B"), order1:=xlDescending, Header:=xlNo

Thank you in advance!
 
Using the code from post#7 make this change
Code:
Sheets("Maintenance Action Word Counts").Range("A1").Resize([COLOR=#ff0000]i+1[/COLOR], 2).Value = Ary
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I got the same error. I included the Msgbox and it displayed the same value as before (11,599).
 
Upvote 0
That I don't understand, especially if it works for smaller sets of data and you are getting an "Application-defined or object-defined error."
 
Upvote 0
Fraid not.
Not when you get the same error with these 2 lines
Code:
Sheets("Maintenance Action Word Counts").Range("A1").Resize(.Count, 2).Value = Application.Transpose(Array(.keys, .items))
Sheets("Maintenance Action Word Counts").Range("A1").Resize([COLOR=#ff0000]i+1[/COLOR], 2).Value = Ary
 
Upvote 0
Problem solved! The text I was searching through contained an "=" in some locations which caused the error. I wrote some code to remove all equal signs from the text and the code works great now!
 
Upvote 0
Glad you sorted it & thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
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