VBA To Delete Values Without Deleting Formulas

VinceF

Board Regular
Joined
Sep 22, 2007
Messages
170
Office Version
  1. 2016
Platform
  1. Windows
Thank you in advance for any assistance.
Novice user, Office 2016, Win 10
With using a command button, I'm looking for a VBA code that would clear only the values in particular cells and ranges without deleting the formulas. I have managed to learn how to replace text in a cell but I am unable to figure out how to clear values while maintaining formulas where needed. If you could post a string that would do this and where I would add it into the existing code that would be very helpful.

Thank You,
VinceF


Private Sub CommandButton1_Click()

Dim warning
warning = MsgBox(Range("A1").Value & " WARNING...!!!! This will reset the entire sheet. Select OK to continue or select CANCEL to continue without resetting", vbOKCancel, "Warning")
If warning = vbCancel Then Exit Sub

Sheets("main").Range("E4").Value = "SKINS ENTRY FEE"

MsgBox "THE FORM HAS BEEN RESET."

End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
What cells do you want to clear?
 
Upvote 0
What cells do you want to clear?
Fluff, There are numerous cells and some ranges that I will need to clear. I'm going to attempt to post the spreadsheet via XL2BB.

Golf Skins Stableford MASTER TEMPLATE 2-14-22DeletsFormulaNeedToFix.xlsm
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAE
2TEAM GENTEAMSHALF SKINSFULL SKINSQUOTA PTSDATATEERATINGSLOPECOR FACMAINPLAYING CONDITIONSBUNKERS
3
4GAME TYPESKINS ENTRY FEESTABLEFORD ENTRY FEESELECT TEERATINGSLOPECR-PARSELECT COURSEPLAYING CONDITIONSBUNKER RELIEF
5
6Stroke Adj.# Skin PlayersSkin PoolHOLE123456789IN101112131415161718OUTTOTAL
7                        
8Skins FrontSkins BackTotal SkinsSkin Value                   
9                          
10
11Team ReqPlayerIndexHDCPStrokesQuotaSkinsF R O N TB A C KTotalsPts
12       
13       
14       
15       
16       
17       
Main
Cell Formulas
RangeFormula
K4K4=IF($I$4="select tee","RATING",IF(I4="blue",'Data Sheet'!$B$5,IF(I4="blue/wh",'Data Sheet'!$B$6,IF(I4="white",'Data Sheet'!$B$7,IF($I4="Red/Wh",'Data Sheet'!$B$8,IF(I4="red",'Data Sheet'!$B$9))))))
L4L4=IF(#REF!="blue",'Data Sheet'!$B$5,IF(#REF!="blue/wh",'Data Sheet'!$B$6,IF(#REF!="white",'Data Sheet'!$B$7,IF(#REF!="Red/Wh",'Data Sheet'!$B$8,IF(#REF!="red",'Data Sheet'!$B$9)))))
M4M4=IF(I4="select tee","SLOPE",IF(I4="blue",'Data Sheet'!$C$5,IF(I4="blue/wh",'Data Sheet'!$C$6,IF(I4="white",'Data Sheet'!$C$7,IF(I4="Red/Wh",'Data Sheet'!$C$8,IF(I4="red",'Data Sheet'!$C$9))))))
N4N4=IF(#REF!="blue",'Data Sheet'!$C$5,IF(#REF!="blue/wh",'Data Sheet'!$C$6,IF(#REF!="white",'Data Sheet'!$C$7,IF(#REF!="Red/Wh",'Data Sheet'!$C$8,IF(#REF!="red",'Data Sheet'!$C$9)))))
O4O4=IF(I4="select tee","CR-PAR",IF(I4="blue",'Data Sheet'!$D$5,IF(I4="blue/wh",'Data Sheet'!$D$6,IF(I4="white",'Data Sheet'!$D$7,IF(I4="Red/Wh",'Data Sheet'!$D$8,IF(I4="red",'Data Sheet'!$D$9))))))
E7E7=IF($E$4="0","",IF($B$4="stableford","",COUNTIF(C12:C51,"*")))
F7F7=IF(B4="game type","",IF(B4="stableford","",IFERROR(E7*E4,"")))
I7I7=IF($I$4="select tee","","Yards")
T7:AB8,J7:R8J7=IF($I$4="select tee","",IF($I$4="blue",'Data Sheet'!C19,IF($I$4="BLUE/WH",'Data Sheet'!C22,IF($I$4="WHITE",'Data Sheet'!C25,IF($I$4="RED/WH",'Data Sheet'!C28,IF($I$4="RED",'Data Sheet'!C31))))))
S7,AC7S7=IF($I$4="select tee","",SUM(J7:R7))
AD7AD7=IF(I4="select tee","",SUM(S7+AC7))
I8I8=IF($I$4="select tee","","HDCP")
I9I9=IF($I$4="select tee","","Par")
T9:AB9,J9:R9J9=IF($I$4="select tee","",'Data Sheet'!C$21)
S9S9=IF(I4="select tee","",SUM(J9:R9))
AC9AC9=IF(I4="select tee","",SUM(T9:AB9))
AD9AD9=IF(I4="select tee","",SUM(S9+AC9))
B9,D9B9=IFERROR('Data Sheet'!B76,"")
E9E9=IFERROR(B9+D9,"")
F9F9=IF(E9="","",IF(B4="game type","",IF(B4="stableford","",'Data Sheet'!S14)))
E12:E17E12=IF($D12="","",SUM(ROUNDUP($D12*$M$4/113+$O$4,0)))
F12:F17F12=IF($C12="","",IF($B$4="stableford","",$E12))
G12:G17G12=IF($B$4="skins","",IF($D12="","",ROUND(IF($D12="","",35-$E12),0)))
AC12:AC17AC12=IF(D12="","",SUM(T12:AB12))
AD12:AD17AD12=IF(D12="","",SUM(S12+AC12))
AE12:AE17AE12=IF($B$4="skins","",IF($D12="","",'Quota Points'!$W6))
S12:S17S12=IF(D12="","",SUM(J12:R12))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I11Expression=($B$4="skins")textNO
C11Expression=ISNUMBER($F$4)textNO
I11Expression=($B$4="stableford")textNO
B6:C6Expression=ISTEXT($B$7)textNO
C11Expression="if(and($B$2=""skins"",$E$2=ismumber)"textNO
B6:C6Expression=ISNUMBER(E4)textNO
C11Expression=ISTEXT($C$12)textNO
B6:C6Expression=$B$4="stableford"textNO
I11Expression=ISTEXT($I$12:$I$51)textNO
I11Expression=ISNUMBER($D$12:$D$51)textNO
I11Expression=$B$4="Stableford"textYES
C11Expression=ISTEXT($B$7)textNO
D11Expression=ISNUMBER($D$12)textNO
D11Expression=ISTEXT($C$12)textNO
B6:C6Expression=$AG$4="Point"textNO
E4Expression=ISNUMBER($F$4)textNO
F4:G4Expression=$B$4="skins"textNO
F4:G4Expression=ISNUMBER($F$4)textNO
F4:G4Expression=$B$4="skins & stableford"textNO
F4:G4Expression=$B$4="stableford"textNO
F4:G4Expression=$B$4="skins"textNO
E4Expression=ISNUMBER($E$4)textNO
E4Expression=$B$4="skins & stableford"textNO
E4Expression=$B$4="stableford"textNO
E4Expression=$B$4="skins"textNO
B4:D4Expression=$B$4="skins & stableford"textNO
B4:D4Expression=$B$4="stableford"textNO
B4:D4Expression=$B$4="skins"textNO
B4:D4Expression=$AC$4="no"textNO
B4:D4Expression=$AC$4="lift rake & place"textNO
AC4:AE4Expression=$AC$4="no"textNO
AC4:AE4Expression=$AC$4="lift rake & Place"textNO
AC4:AE4Expression=$W$4="lift - clean - place fairway only"textNO
AC4:AE4Expression=$W$4="lift - clean - place"textNO
AC4:AE4Expression=$W$4="playing ball down"textNO
W4:AB4Expression=$W$4="Lift - Clean - Place Fairway Only"textNO
W4:AB4Expression=$W$4="lift - clean - place"textNO
W4:AB4Expression=$W$4="playing ball down"textNO
W4:AB4Expression=$I$4="Red"textNO
W4:AB4Expression=$I$4="Red/Wh"textNO
W4:AB4Expression=$I$4="White"textNO
W4:AB4Expression=$I$4="Blue/Wh"textNO
I4:J4Expression=$I$4="Red"textNO
I4:J4Expression=$I$4="Red/Wh"textNO
I4:J4Expression=$I$4="white"textNO
I4:J4Expression=$I$4="Blue/Wh"textNO
I4:J4Expression=$I$4="Blue"textNO
I4:J4Expression=$Q$4="paint creek country club"textNO
Q4:V4Expression=$Q$4="paint creek country club"textNO
W4:AB4Expression=$I$4="Blue"textNO
F9:G9Expression=ISERROR(F9)textNO
H13:H51Cell Valuecontains "No"textNO
H12Cell Valuecontains "No"textNO
Cells with Data Validation
CellAllowCriteria
I4:J4List='Data Sheet'!$A$4:$A$9
Q4:V4List='Data Sheet'!$X$2:$X$6
W4:AB4List='Data Sheet'!$N$35:$N$38
AC4:AE4List='Data Sheet'!$K$12:$K$14
I12:I17List='Data Sheet'!$M$11:$M$13
B12:B17List='Data Sheet'!$M$11:$M$13
B7:C7List='Data Sheet'!$J$36:$J$38
B4:D4List='Data Sheet'!$F$3:$F$6
E4List='Data Sheet'!$Y$6:$Y$26
F4:G4List='Data Sheet'!$AA$2:$AA$22
 
Upvote 0
That doesn't really answer my question. I have no idea which of those cells you want to clear.
 
Upvote 0
This is a spreadsheet that many of the cells get populated by either direct input, dropdown cells or based on input from other cells. I would need to clear values in specific cells, ranges of cells, etc..
Some examples would be, B12:B17, C12:C17, D12:D17 are all direct input. C4, E4 and F4 are populated by a drop down box and the text that's in there now would need to be replaced when reset (I figured out how to do that). J12:R12, J13:R13, etc. are populated by direct input. With very, very limited knowledge of VBA would there not be a string to add in the code that would delete the value of the cell while preserving the formula? Everything I have so far, I did by googling and trial and error.
I hope this helps.
Thank You

VinceF
 
Upvote 0
This will clear all cells that do not contain a formula from row12 to 17
VBA Code:
   Range("12:17").SpecialCells(xlConstants).ClearContents
 
Upvote 0
This will clear all cells that do not contain a formula from row12 to 17
VBA Code:
   Range("12:17").SpecialCells(xlConstants).ClearContents
Thank You Fluff...it appears to be working as needed (sorry for my limited skills and my inability to express myself adequately)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,424
Members
448,896
Latest member
MadMarty

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top