![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Location: Ted Davenport
Posts: 10
|
I need a macro (or Excel function) that will delete the data from a spreadsheet but leave the formulas intact. I don't want to hide the data, I want to delete the data so I can use the same formulas for adding other data. "Clear All" won't leave the formulas intact. I also want to leave the field names intact. I only want to delete the data (numbers). Thanks in advance for you help
|
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
Hi,
Try ---------------- Sub test() Dim DataRng As Range, UsedCell As Range Set DataRng = ActiveSheet.UsedRange For Each UsedCell In DataRng If Not UsedCell.HasFormula Then UsedCell.ClearContents Next UsedCell End Sub ----------------- Bye, Jay |
|
|
|
|
|
#3 |
|
New Member
Join Date: Apr 2002
Location: Ted Davenport
Posts: 10
|
Thanks Jay for the reply. Although I am not proficient at programming language, it appears your foumula will delete my field names which I don't want to do. Is this the case.? Agains thanks.
|
|
|
|
|
|
#4 | |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
This macro will clear numeric
Values only. Quote:
[ This Message was edited by: TsTom on 2002-04-25 06:57 ] |
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Mar 2002
Posts: 363
|
Another way without using VBA
Select Edit > Goto from the menu, click Special, click constant, choose the data type: Numbers, Text, etc. Click OK. Press Delete.
__________________
It's never too late to learn something new. Ricky |
|
|
|
|
|
#6 | |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
Quote:
The following is my correction, which matches what TsTom just supplied, but with the full sub. Also, Ricky's response will work, too, I believe. Sub test() Dim DataRng As Range, UsedCell As Range Set DataRng = ActiveSheet.UsedRange For Each UsedCell In DataRng If IsNumeric(UsedCell) And _ Not UsedCell.HasFormula Then UsedCell.ClearContents Next UsedCell End Sub Bye, Jay |
|
|
|
|
|
|
#7 |
|
New Member
Join Date: Apr 2002
Location: Ted Davenport
Posts: 10
|
Hey Guys,
Thanks. Since I couldn't figure out how to save the routines and run them, I chose Ricky's method and it works perfectly. I appreciate all the help. Mucho gracious. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|