Slow opening of Excel file

assurdo

New Member
Joined
Sep 22, 2014
Messages
13
Hello,
I've a file Excel with a pivot table and some macro. When I open this file, I need to wait some minutes (I can see the logo of Excel and the writing "Calculation ongoing (8 thread)").
Can be the presence of this macro? It uses to delete some rows.

Code:
  Dim LR3 As Long, i3 As Long


With Sheets("Import")
    LR3 = .Range("A" & .Rows.Count).End(xlUp).Row


    For i3 = LR3 To 2 Step -1
        If IsNumeric(.Range("A" & i3).Value) = False And _
        Len(.Range("A" & i3).Value) > 0 Then


        Else
            .Rows(i3).Delete
        End If
    Next i3
End With

How can I resolve this problem? Thank you.
 
Last edited by a moderator:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
For sure it's that macro, because if I delete it, the workbook opens immediatly.
How can I change this code? It delete rows starting from a sheet of 3500 rows. And it delete most of them (more than 90% of the rows)
 
Upvote 0
Try this instead:

Code:
  Dim LR3 As Long, i3 As Long
  Dim data As Variant
    Dim rangeToDelete As Range

    With Sheets("Import")
        LR3 = .Range("A" & .Rows.Count).End(xlUp).Row
        data = .Range("A2:A" & LR3).Value
    
        For i3 = LBound(data) To UBound(data)
            If Not IsNumeric(data(i3, 1)) And _
            Len(data(i3, 1)) <> 0 Then
    
    
            Else
                If rangeToDelete Is Nothing Then
                    Set rangeToDelete = .Range("A" & i3 + 1)
                Else
                    Set rangeToDelete = Union(rangeToDelete, .Range("A" & i3 + 1))
                End If
            End If
        Next i3
    End With
    If Not rangeToDelete Is Nothing Then rangeToDelete.EntireRow.Delete
 
Upvote 0
Try this instead:

Code:
  Dim LR3 As Long, i3 As Long
  Dim data As Variant
    Dim rangeToDelete As Range

    With Sheets("Import")
        LR3 = .Range("A" & .Rows.Count).End(xlUp).Row
        data = .Range("A2:A" & LR3).Value
    
        For i3 = LBound(data) To UBound(data)
            If Not IsNumeric(data(i3, 1)) And _
            Len(data(i3, 1)) <> 0 Then
    
    
            Else
                If rangeToDelete Is Nothing Then
                    Set rangeToDelete = .Range("A" & i3 + 1)
                Else
                    Set rangeToDelete = Union(rangeToDelete, .Range("A" & i3 + 1))
                End If
            End If
        Next i3
    End With
    If Not rangeToDelete Is Nothing Then rangeToDelete.EntireRow.Delete

Grazie RoryA, ora il file Excel si apre immediatamente e fa lo stesso identico lavoro di prima. Posso chiederti in cosa si differenzia dal codice precedente? Per imparare! Grazie
 
Upvote 0
Grazie RoryA, ora il file Excel si apre immediatamente e fa lo stesso identico lavoro di prima. Posso chiederti in cosa si differenzia dal codice precedente? Per imparare! Grazie

Thank you RoryA, now the file opens immediatly. What's the difference between this code and the old one? To learn..Thank you.
 
Upvote 0
It doesn't delete one row at a time, which is always slow. It builds up a block of rows that need deleting and then deletes them all at once.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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