Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

"CLEAR" Macro

Posted on 2012-12-29
5
Medium Priority
?
394 Views
Last Modified: 2012-12-30
Hello Experts!

I have a spreadsheet, that calculates figures for me on a daily basis.  Each day, I end up clearing out specific cells and/or ranges to bring the spreadsheet back to Day 1.

What would be the macro/code I could copy and paste into my spreadsheet (Yes, I know where to paste a macro, I just don't have a clue how to write it) to clear specific cells & ranges.

IE - I am going to add a button to my spreadsheet, that when pressed does the following...

1.)  "Clear Contents" of range E:I
2.)  "Clear Contents" of range C7:C8
3.)  "Clear Contents" of cell C10

Is this possible?

Thank you in advance for your help!

~ Geekamo
0
Comment
Question by:Geekamo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38730372
Range(E:I).Select
Selection.ClearContents
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38730374
Sorry.

Range("E:I").Select
Selection.ClearContents
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 2000 total points
ID: 38730377
If you are using 2007 or above then
From the Developer tab
Insert > Form controls > Button
In the Assign macro window type a name for your macro
Click New
Type this between the Sub and End Sub lines

Activesheet.range("E:I, C7:C8, C10").clearcontents

Open in new window


Close the VBA window
You are now ready to go

If you do not see the Developer tab on the ribbon menu then you have to enable it from the excel settings
0
 
LVL 7

Expert Comment

by:karunamoorthy
ID: 38730406
After inserting command button into worksheet, say (sheet1),
then double click on the inserted command button and write code and it will look like this,

Private Sub CommandButton1_Click()
    Sheet1.Select
    Columns("E:I").Select
    Selection.ClearContents
    Range("C7:C8").Select
    Selection.ClearContents
    Range("C10").Select
    Selection.ClearContents
End Sub

Now if you click the command button, then you will find the code  will do the real magic for you.

hope this helps.
0
 
LVL 1

Author Comment

by:Geekamo
ID: 38731333
@ ssaqibh

Thank you very much!  Your line of code worked beautifully.

@ everyone

Thank you all for your input.

~ Geekamo
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question