Macro on Open to clear named range

gelu

Board Regular
Joined
Sep 30, 2022
Messages
85
Office Version
  1. 2021
Platform
  1. Windows
Hello,

Any help would be greatly appreciated! Trying to delete a named range when the workbook opens.
....
Application.Goto Reference:="Clienti_Clear_Range" '(name for range A8:K900
Selection.ClearFormats
Selection.ClearContents
....

I tried this:

Private Sub Workbook_Open()
'Updated by Extendoffice 20190712
Application.EnableEvents = False
Worksheets("Clienti").Range("A8:K900").Value = ""
Application.EnableEvents = True
End Sub


It does work from within the open worklbook but not when the worksheet opens ...

Thank you!,

Gelu
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi Gelu,

code must be placed in ThisWorkbook, not a standard module.

Ciao,
Holger
 
Upvote 0
It works beautifully,

Thank you Holger! :)

To delete a bunch of named ranges should I do this?:

Private Sub Workbook_Open()
'Updated by Extendoffice 20190712
Application.EnableEvents = False
Worksheets("Clienti").Range("A8:K900").Value = ""
Worksheets("Sheet2").Range(Name2).Value = ""
Worksheets("Sheet3").Range(Name3).Value = ""

Application.EnableEvents = True
End Sub


Gelu
 
Upvote 0
Hi gelu,

the Names need to be put in quotes like
Code:
Private Sub Workbook_Open()
'https://www.mrexcel.com/board/threads/macro-on-open-to-clear-named-range.1218040/
'Updated by Extendoffice 20190712
  Application.EnableEvents = False
  Worksheets("Clienti").Range("A8:K900").Value = ""
  Worksheets("Sheet2").Range("Name2").Value = ""
  Worksheets("Sheet3").Range("Name3").Value = ""
  Application.EnableEvents = True
End Sub
Ciao,
Holger
 
Upvote 0
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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