Extract numbers from text string (within row range) and sum

Donbozone

New Member
Joined
Mar 28, 2020
Messages
45
Office Version
  1. 365
Platform
  1. Windows
Hi.

I couldnt find solution for a simple problem at first sight.

In a short, I have a row with some codes in cells. These codes were made by letters and digits.

For example:

CE4, BV8, G2, CX, AC - these are codes in a separate cells let say in a range (a1:a5)

What I need is a function or vba code which is going to extract digits from each cell and then make a sum of extracted values.

In this case result would be: 4+8+2=14

Of course, I have many rows, so formula in a6 would be best solution, so I could just pull it down to the last row.

Thanks for any help.
 
I cant believe Im making such a mistakes..

These are days in Croatian: subota, nedjelja, ponedjeljak, utorak, srijeda, četvrtak and petak. I forgot that both, Saturday and Wednesday starts with (S)
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I cant believe Im making such a mistakes..

These are days in Croatian: subota, nedjelja, ponedjeljak, utorak, srijeda, četvrtak and petak. I forgot that both, Saturday and Wednesday starts with (S)
VBA Code:
If InStr(1, "NESU", Left(Cells(1, c.Column - ((c.Column - rVals.Column) Mod 2)).Value, 2), 1) > 0 And IsNumeric(Right(c.Value, 1)) Then Sum_WE = Sum_WE + Right(c.Value, 1)
 
Upvote 0
Now it summarize all days..
Not for me.

VBA Code:
Function Sum_WE(rDays As Range, rVals As Range) As Long
  Dim c As Range
  
  For Each c In rVals
    If InStr(1, "NESU", Left(Cells(1, c.Column - ((c.Column - rVals.Column) Mod 2)).Value, 2), 1) > 0 And IsNumeric(Right(c.Value, 1)) Then Sum_WE = Sum_WE + Right(c.Value, 1)
  Next c
End Function

Donbozone 2020-04-05 1.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1ponedjeljakutoraksrijedačetvrtakpetaksubotanedjeljaponedjeljakutoraksrijedačetvrtakpetaksubotanedjeljaSum Weekend
2CE4BV6G2CXACBV8ABVC5AB2CC722
3XXYY0
4AA4AA4B0A99
Sheet1
Cell Formulas
RangeFormula
AC2:AC4AC2=Sum_WE(A$1:AB$1,A2:AB2)
 
Upvote 0
I will check once again, but seems not important at the moment.

My colleague has just informed me that she actually needs to count codes that have digits in string and belong to weekend days (subota, nedjelja).

In your example in AC2 instead of sum (result 22), it supposed to be count (result 4).

I really apologize for this inconvenience.
 
Upvote 0
@Peter,

I can not change your UDF, because the days, in my sheet, are in one cell (not in two).
Can you please help me.
 
Upvote 0
VBA Code:
If InStr(1, "NESU", Left(Cells(1, c.Column - ((c.Column - rVals.Column) Mod 2)).Value, 2), 1) > 0 And IsNumeric(Right(c.Value, 1)) Then Sum_WE = Sum_WE + Right(c.Value, 1)
Here is a shorter way to write the above code line...
VBA Code:
If Intersect(c.EntireColumn, Rows(1)).MergeArea(1).Value Like "[SsNn][UuEe]*" Then Sum_WE = Sum_WE + Val(StrReverse(c.Value))
By the way Peter, you do not need the first argument in your function as you seem to no longer be using it.
 
Last edited:
Upvote 0
My colleague has just informed me that she actually needs to count codes that have digits in string and belong to weekend days (subota, nedjelja).
Does this modification to Peter's code work for you (note I have shortened his If..Then statement using the technique I employed in Message #17)...
VBA Code:
Function Sum_WE(rVals As Range) As Long
  Dim c As Range
  For Each c In rVals
    If Intersect(c.EntireColumn, Rows(1)).MergeArea(1).Value Like "[SsNn][UuEe]*" Then Sum_WE = Sum_WE - (c.Value Like "*#")
  Next c
End Function
 
Upvote 0
No, it seems it does not work.

Was it changed in a way not to make sum, but to count codes that have digit inside and belong to non-working days?
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,920
Members
448,533
Latest member
thietbibeboiwasaco

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