VBA Don't sum strikethrough not working with conditional format

NikoDDS

New Member
Joined
Nov 8, 2021
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
The VBA code works, when I directly strikethrough a cell which has a value in currency entered with NO conditional formatting.
If I enter a conditional format in column C to strikethrough both cells in column C & D and the column D has a formula based on numeric number entered in column A, the sum of column D still adds the value in strikethrough cells
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
The sum of Column D is done through the VBA code? Is it a macro or a UDF (user defined function)?
 
Upvote 0
Its a macro in separate Module 1

VBA Code:
Public Function ExcStrike(pWorkRng As Range) As Long
'Update 20140819
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
    If Not pRng.Font.Strikethrough Then
        xOut = xOut + pRng.Value
    End If
Next
ExcStrike = xOut
End Function

with =excstrike(D6:D10)" in D11
 
Last edited by a moderator:
Upvote 0
How about using a helper function like
VBA Code:
Public Function ExcStrike(pWorkRng As Range) As Long
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
   If Not Evaluate("IsStrike(" & pRng.Address & ")") Then
        xOut = xOut + pRng.Value
    End If
Next
ExcStrike = xOut
End Function
Private Function IsStrike(Cl As Range) As Boolean
   IsStrike = Cl.DisplayFormat.Font.Strikethrough
End Function
 
Upvote 0
How about using a helper function like
VBA Code:
Public Function ExcStrike(pWorkRng As Range) As Long
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
   If Not Evaluate("IsStrike(" & pRng.Address & ")") Then
        xOut = xOut + pRng.Value
    End If
Next
ExcStrike = xOut
End Function
Private Function IsStrike(Cl As Range) As Boolean
   IsStrike = Cl.DisplayFormat.Font.Strikethrough
End Function
Yes the helper function helped, Thanks
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Using the same function in multiple (3) sheets in a workbook, the don't sum strikethrough works in the first sheet, then as the strikethrough is done in the 2nd sheet and 3rd sheet, the function does not work in 1st sheet. When I redo the function in the 1st sheet, it does not work in the 2nd and 3rd sheet
Not sure how to upload the whole workbook
 
Upvote 0
How about
VBA Code:
   If Not pRng.Worksheet.Evaluate("IsStrike(" & pRng.Address & ")") Then
 
Upvote 0
Yes that seems to work, all worksheets are calculating correctly, Thanks
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,862
Members
449,052
Latest member
Fuddy_Duddy

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