Macro Slow

WindowGuy

New Member
Joined
Sep 12, 2023
Messages
18
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hi There. I am not good at this so please bare with me. I copied the following code from the internet to reset all my dropdownlist but it is SOOOOO slow. Like literally 4+ minutes to reset my page. I created myself a quoting program for my small business and would like to default to start fresh again on all dropdown lists. please help and see what i copied and used which is slow. Again i barely understand this so easy on my with terms of answers.

VBA Code:
Sub DropDownListToDefault()
    Dim oCell As Range
   
    For Each oCell In ActiveSheet.UsedRange.Cells
        If HasValidation(oCell) Then
            oCell.Value = "'- Choose Option -"
            End If
    Next
   
End Sub

Function HasValidation(cell As Range) As Boolean
    Dim t: t = Null
   
    On Error Resume Next
    t = cell.Validation.Type
    On Error GoTo 0
   
    HasValidation = Not IsNull(t)
End Function

Thanks in advance.

George.
 
Last edited by a moderator:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hey there, try this, see if it speeds things up.

VBA Code:
Sub DropDownListToDefault()
Application.Calculation = xlManual
Application.ScreenUpdating = False


Dim oCell As Range

For Each oCell In ActiveSheet.UsedRange.Cells
If HasValidation(oCell) Then
oCell.Value = "'- Choose Option -"
End If
Next

End Sub

Function HasValidation(cell As Range) As Boolean
Dim t: t = Null

On Error Resume Next
t = cell.Validation.Type
On Error GoTo 0

HasValidation = Not IsNull(t)

Application.Calculation = xlAutomatic
Application.ScreenUpdating = True


End Function
 
Upvote 0
Hey there, try this, see if it speeds things up.

VBA Code:
Sub DropDownListToDefault()
Application.Calculation = xlManual
Application.ScreenUpdating = False


Dim oCell As Range

For Each oCell In ActiveSheet.UsedRange.Cells
If HasValidation(oCell) Then
oCell.Value = "'- Choose Option -"
End If
Next

End Sub

Function HasValidation(cell As Range) As Boolean
Dim t: t = Null

On Error Resume Next
t = cell.Validation.Type
On Error GoTo 0

HasValidation = Not IsNull(t)

Application.Calculation = xlAutomatic
Application.ScreenUpdating = True


End Function
at 8+ minutes and still going definetley not better :(
 
Upvote 0
How about
VBA Code:
Sub DropDownListToDefault()
   Dim Rng As Range
   
   Application.ScreenUpdating = False
   On Error Resume Next
   Set Rng = ActiveSheet.UsedRange.SpecialCells(xlCellTypeAllValidation)
   Rng.Value = "'- Choose Option -"
   On Error GoTo 0
End Sub
 
Upvote 0
Solution
How many dropdown lists are on the sheet?
about 300.... at 20 mins from the last guys sugestion definetly worse. i dont know how to stop it i tried the window key+end but it's not doing anything....
 
Upvote 0
How about
VBA Code:
Sub DropDownListToDefault()
   Dim Rng As Range
  
   Application.ScreenUpdating = False
   On Error Resume Next
   Set Rng = ActiveSheet.UsedRange.SpecialCells(xlCellTypeAllValidation)
   Rng.Value = "'- Choose Option -"
   On Error GoTo 0
End Sub
you my friend are a genius. It was instant. Unbelievable thank you so much you have no idea how happy I am.. Now anyway to make it work when sheet protected?
 
Upvote 0
You will need to unprotect the sheet at the start of the code & re-protect it at the end.
 
Upvote 0
You will need to unprotect the sheet at the start of the code & re-protect it at the end.
Hi there is there no other way? I want to give this sheet to an assistant to use for quoting but cant unlock it for them i need it to stay locked.
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,308
Members
449,152
Latest member
PressEscape

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