Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I clear contents from a specific range in Excel?

Status
Not open for further replies.

mlrmlr

Technical User
Mar 17, 2006
168
US
Hello,

I use this function to open an existing Excel workbook, clear the contents and paste new data. This has been working great for the most part. The problem is the "ClearContents" is erasing all of my data and formulas and I would like to start at a specific range. Can I specify the range I would like to clear? The data I would like to clear starts at A22:J100.

<BEGIN CODE>
'Open Excel report and clear existing data

Set myXL = CreateObject("Excel.Application")
Set myWB = myXL.Workbooks.Open("O:\WO.xls")
myWB.Sheets("Daily_WO_Report1").UsedRange.ClearContents
myWB.Save
myXL.Quit
Set myXL = Nothing
<END CODE>

Appreciate your help.
 
Turn on your macro recorder (Tools > Macros > Record New Macro) and do what you want.

Observe the code that was created.

If you have any questions, please create a new thread for this VBA/Macro-specific topic in forum707.


[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
Hey anotherhiggins thanks for the macro suggestion.

I totally forgot this was a VBA issue.

Sorry. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top