clear defined named cells' contents

  • Thread starter Thread starter Mint
  • Start date Start date
M

Mint

i want to make a vba sub in excel file.
My sub is to clear the selected cells.
The cells are all in my defined region.
How can i write the such program.
How can i select the region?
Name("myregion").selected seems wrong.
please advice.
many thanks.
 
Try either
Range("myregion").Clear
or
Range("myregion").ClearContents

Clear will remove formatting and comments as well as the cell contents.
 
many thanks
Sub delete()

Range("Week1").Clear

End Sub

but:
Run-Time error '1004'
Method 'Range' of object '_Global' failed.
Do i have to active a worksheet?
please advice.
 
not really, just qualify the range:

Sub clear_range()
Dim ws As Worksheet
Set ws = Worksheets("Sheet1") ' or whatever the name is
ws.Range("Week1").Clear
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top