Vba: Delete Contents From Range Very Slowly

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..

how to make this code more fast to delete / clear contents a range (C2:BU7130)
this code work but very slowly
VBA Code:
Sub DeleteRange()
 Dim wkbCrntWorkBook As Workbook
    Dim wkbSourceBook As Workbook
    Dim rngSourceRange As Range
        Set wkbCrntWorkBook = ActiveWorkbook
          Set wkbSourceBook = ActiveWorkbook
           With Application.InputBox(prompt:="Select range", Title:="Range", Default:="[B]C2:BU7130[/B]", Type:=8)
             .SpecialCells (xlCellTypeConstants)
            .ClearContents
            End With
                   End Sub

thank in advance

.susanto
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi Muhammad.

What about this short code? Or do you want to select which range to delete when you run your macro?

VBA Code:
Sub DeleteRange()
    Range("C2:BU7130").Select
    Selection.ClearContents
End Sub
 
Upvote 0
hi mkuzne, it work for me, but why still slowly?

all rows is visible nothing hidden row​

 
Upvote 0
Well in my test file it works instantly.
Can you upload your file somehow so we can test it in our environment?
 
Upvote 0
hi, sorry about that cause i can't upload for a reason security, my file size is over 7,4 mb
 
Upvote 0
Don't select
VBA Code:
Sub DeleteRange()
    Range("C2:BU7130").ClearContents
End Sub
 
Upvote 0
I guess that could also be the cause of your problem...your file obviously contains a looooooot of data, judging by the size. Does it work slowly calculating anything or any funcfion or Just when running macro?

Maybe try one thing. On the tab Formulas Turn off Automatic calculation and set it to Manual?

 
Upvote 0
Solution
As @mkuzner mentioned....turn off automatic calculation until all cells are cleared
 
Upvote 0
hi guys.
i turn off automatic calculation then formula
Sub DeleteRange()
Range("C2:BU7130").ClearContents
End Sub
the result is good, more faster
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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