i want to calculate only numbers and ignore date value

Mishoshow

New Member
Joined
Sep 6, 2021
Messages
34
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hi Guys,,

i want to calculate only numbers and ignore date value

that the vba code i used it to calculate the number but still calculate the date too

Function SumNum(rng As Range) As Double

Dim cell As Range
Dim tot As Double

For Each cell In rng
tot = tot + Val(cell)
Next cell

SumNum = tot

End Function
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    210.5 KB · Views: 33

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Welcome to the MrExcel board!

You haven't said just what you want this function for or where it will be used but as a guess could you use a normal function like this?

Excel Formula:
=SUMIF(B$1:H$1,"Amount",B2:H2)
 
Upvote 0
Welcome to the MrExcel board!

You haven't said just what you want this function for or where it will be used but as a guess could you use a normal function like this?

Excel Formula:
=SUMIF(B$1:H$1,"Amount",B2:H2)
i want to sum from C2 to H2 and ignore date value at the same time without using B1 to H1 ,, i tried vba code but the result bring a different between the code and the sum Manuel

that's the code i used ,, if u can add something to the code to ignore date i'll be thankful..

Function SumNum(rng As Range) As Double

Dim cell As Range
Dim tot As Double

For Each cell In rng
tot = tot + Val(cell)
Next cell

SumNum = tot

End Function
 
Upvote 0
Then give this UDF a try

VBA Code:
Function SumNum(rng As Range) As Double
  Dim cell As Range
  
  For Each cell In rng
    If IsNumeric(cell.Value) And Not IsDate(cell.Value) Then SumNum = SumNum + cell.Value
  Next cell
End Function
 
Upvote 0
Then give this UDF a try

VBA Code:
Function SumNum(rng As Range) As Double
  Dim cell As Range
 
  For Each cell In rng
    If IsNumeric(cell.Value) And Not IsDate(cell.Value) Then SumNum = SumNum + cell.Value
  Next cell
End Function
Perfect ,, thanks for your time
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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