Excluding "Strikethrough" numbers from a summation

NextYearSox

Active Member
Joined
Oct 24, 2003
Messages
287
I have a list of numbers that I want to sum (easy enough) - but periodically want to format on or more of the set using the Strikethrough format effect to remove the particular number from the set (though I still want to be able to see the number.

I don't particularly care how I "strikethrough" but I'd like to keep this kind of effect. Is this possible without VBA?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
As far as I know you're going to need a macro of some sort to detect the strikethrough formatting.

However, you can try a function macro. You can then use it just like a normal function.

Put the following code in a module in your workbook:

Public Function STRIKESUM(ByVal myRange As Range)
Dim cell As Range, x As Integer

For Each cell In myRange
If cell.Font.Strikethrough = False Then x = x + cell
Next cell
STRIKESUM = x
End Function

For example, let's say your numbers are in A1:A10. You can use =STRIKESUM(A1:A10) as your formula, and it should return the sum of all of the numbers in that range that do not have a strike.

One downside of this is that the formula will not update automatically if changes are made to A1:A10--you will need to press F9 to recalculate.
 
Upvote 0
I'm not familiar with Function Macro's - so I just copied and pasted your macro. But had no luck. When I enter the data, and use the =strikesum command, EXCEL returns: #VALUE. Am I missing something?
 
Upvote 0
Are you actually entering a range for strikesum?

eg

=strikesum(A1:A100)
 
Upvote 0
Yep, that should do it. Did you put it in a separate module? You don't want to put it in any of the Sheet or ThisWorkbook modules.
 
Upvote 0
yup - that's exactly what I did. My data is in cells k4:k16, my formula is in k17 [=STRIKESUM(K4:K16)], and my macro is as follows:



Public Function STRIKESUM(ByVal myRange As Range)
Dim cell As Range, x As Integer

For Each cell In myRange
If cell.Font.Strikethrough = False Then x = x + cell
Next cell
STRIKESUM = x
End Function
 
Upvote 0
I figured it out (I think). My numbers were too big - so I Dim'd x as double, which seems to have solved the problem.

Thanks everyone! :p
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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