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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel, Clear selected - a Cool Reset Button ???

Status
Not open for further replies.

mxw

Programmer
Joined
Jul 24, 2001
Messages
79
Location
CA
Good Morning! 8am here!

I'm wondering ...
I'd like to have a little 'Reset Button' a cell on a open worksheet page (its not linked to any other) that I can click/select (hit enter) and it will clear all selected cells without clearing the formulas so the worksheet is cleared to start over.

It that possible?

thanks
mxw ~Eeegads~
 
Hi,

If you know the cells exactly then you can use Range object with an array like below (A1,A3,A5 and A9 are sample cells to clear):

Range("A1,A3,A5,A9").ClearContents

Or for a general way (you don't know exact cells or they are too much),

1- (They are too much) Select those cells (by using CTRL key if they needs multiply selection) then name this selecting like 'MyCells' and then use this code:

Range("MyCells").ClearContents

2- (You don't know the exact cells) Assign this macro to your Reset Button.

Sub ClearNoneFormula()
Dim mycell
Application.ScreenUpdating = False
For Each mycell In Sheet1.UsedRange.Cells
If Not mycell.HasFormula = True Then
mycell.ClearContents
End If
Next mycell
Application.ScreenUpdating = True
End Sub

Regards
Oz
 
The following line of code will clear all except formulas form any selected cells :

Selection.SpecialCells(xlCellTypeConstants, 23).ClearContents.

If you want to clear all cells (except formulas) in a contiguous range that includes the activecell use :

ActiveCell.CurrentRegion.SpecialCells(xlCellTypeConstants, 23).ClearContents

The following would do the same for the entire worksheet :

Cells.SpecialCells(xlCellTypeConstants, 23).ClearContents

A.C.
 
Hello Oz/A.C.!

Thank you for the quick reply!
I apologize that I didn't mention that I'm a newbie with no manuals. Eeegads eh?

I'll try 'em out as well as the one
=======================================
Zathras suggested, making this macro ...

Sub ClearText()

' Clears data entry cells and leaves formulas

Dim c As Range
MsgBox ActiveSheet.UsedRange.Address
For Each c In ActiveSheet.UsedRange
If (c.Text <> &quot;&quot; And c.HasFormula = False) Then
c.ClearContents
End If
Next c
End Sub
=======================================
I may be back ;)
mxw ~Eeegads~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top