VBA Clear Contents but not formulas

bullcreel

Board Regular
Joined
Aug 25, 2016
Messages
148
I have the formula below and I want it to clear the contents but not the formulas. It is still clearning the formulas. I also added in the SpecialCells...infront of .Style="Normal" just to see if that was the problem, however, I dont think I need that part.

Sub GameStatsStl()

Dim CurrentRow

For CurrentRow = 4 To 39
For CurrentColumn = 2 To 17
Sheets("Stl").Cells(CurrentRow, CurrentColumn).Value = Sheets("StlGame").Cells(CurrentRow, CurrentColumn).Value + Sheets("Stl").Cells(CurrentRow, CurrentColumn).Value

Next CurrentColumn
Next CurrentRow

For CurrentRow = 43 To 60
For CurrentColumn = 2 To 19
Sheets("Stl").Cells(CurrentRow, CurrentColumn).Value = Sheets("StlGame").Cells(CurrentRow, CurrentColumn).Value + Sheets("Stl").Cells(CurrentRow, CurrentColumn).Value
Next CurrentColumn
Next CurrentRow

Sheets("StlGame").Range("b4:R36").SpecialCells(xlConstants).ClearContents
Sheets("StlGame").Range("b4:R36").SpecialCells(xlConstants).Style = "Normal"
Sheets("StlGame").Range("b43:P60").SpecialCells(xlConstants).ClearContents
Sheets("StlGame").Range("b43:P60").SpecialCells(xlConstants).Style = "Normal"
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
A formula is a content of a cell and so it will always be cleared by clearcontents, there is no way around that.

If you want the cell to appear blank then you need to adjust the formula to show "" in whatever circumstance you are trying to clear the contents, or clear the cells and reapply the formula with code when you want to get a result from the formula.
 
Upvote 0
This is what I want to do. Lets say I already have data in Cells:
A1 is 22
A2 is 32
A3 is 42

Then I get the results from a game in another worksheet of:

A1 is 20
A2 is 30
A3 is 40

What I want to do is just have the 2nd worksheet update the 1st work sheet so that in the 1st worksheet:

A1 is now 42 (22+20)
A2 is now 62 (32+30)
A3 is now 82 (42+40)
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,702
Members
449,048
Latest member
81jamesacct

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