excel macro overflow problem

tuytuy

Board Regular
Joined
Mar 28, 2013
Messages
75
hi,
i have a table of 91400 rows and i've tried to run this macro, but it always gets suck and ends up not responding. The original code had integer instead of long, i though by changing this it would help, but it doesn't seem to change anything...

Code:
Sub SheetBBM ()
'Creating BlackBerry table


Sheets.Add.Name = "BlackBerry"
ActiveWorkbook.Sheets("Section_14").Activate
Dim LSearchRow As Long
   Dim LCopyToRow As Long
   'Start search in row 3
   LSearchRow = 3
   
   'Start copying data to row 2 in Sheet2 (row counter variable)
   LCopyToRow = 2
   
   While Len(Range("A" & CStr(LSearchRow)).Value) > 0
   
      'If value in column E = "Mail Box", copy entire row to Sheet2
      If Range("K" & CStr(LSearchRow)).Value = "BlackBerry usage" Then
      
         'Select row in Sheet1 to copy
         Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
         Selection.Copy
         
         'Paste row into Sheet2 in next row
         Sheets("BlackBerry").Select
         Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
         ActiveSheet.Paste
         
         'Move counter to next row
         LCopyToRow = LCopyToRow + 1
         
         'Go back to Sheet1 to continue searching
         Sheets("Section_14").Select
         
      End If
      
      LSearchRow = LSearchRow + 1
      
   Wend
   
   'Position on cell A3
   Application.CutCopyMode = False
   Range("A3").Select
End sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Which line causes the error?

Incidentally I think that you could replace

Code:
         Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select          
Selection.Copy                    
'Paste row into Sheet2 in next row          
Sheets("BlackBerry").Select          
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select          
ActiveSheet.Paste

with

Code:
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Copy Destination:=Sheets("BlackBerry").Rows(CStr(LCopyToRow))
 
Upvote 0
Are the CStr()'s necessary? not sure here... just something to consider
 
Upvote 0
That shouldn't happen if you declare it as Long rather than Integer.

Try:
Code:
Sub SheetBBM()
'Creating BlackBerry table


   Dim LSearchRow             As Long
   Dim LCopyToRow             As Long


   With Application
      .ScreenUpdating = False
      .Calculation = xlCalculationManual
   End With
   Sheets.Add.Name = "BlackBerry"


   'Start search in row 3
   LSearchRow = 3


   'Start copying data to row 2 in Sheet2 (row counter variable)
   LCopyToRow = 2
   With ActiveWorkbook.Sheets("Section_14")
   
      While Len(.Range("A" & LSearchRow).Value) > 0


         'If value in column E = "Mail Box", copy entire row to Sheet2
         If .Range("K" & LSearchRow).Value = "BlackBerry usage" Then


            'Select row in Sheet1 to copy
            .Rows(LSearchRow).Copy Sheets("BlackBerry").Cells(LCopyToRow, "A")


            'Move counter to next row
            LCopyToRow = LCopyToRow + 1


         End If


         LSearchRow = LSearchRow + 1


      Wend


      'Position on cell A3
      .Activate
      .Range("A3").Select
   End With


   With Application
      .Calculation = xlCalculationAutomatic
      .ScreenUpdating = True
   End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,202,917
Messages
6,052,548
Members
444,591
Latest member
fauxlidae

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