Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8419283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:33:58+00:00 2026-06-10T02:33:58+00:00

I try create new function in Excel, witch will counting given values (something like

  • 0

I try create new function in Excel, witch will counting given values (something like SUM function, but only with given prefix).

  A
---------    
1|AA30  
2|AA10 
3|BC446 
4|AA10

// result will be 50  on SUM_PREFIX(A1:A4;"AA")

Problem is, when the value is in the form e.g AA10,434 or AA4.43. Could me anyone help me with my problem? This is my first stript in VB.

 Function SUM_PREFIX(Data As Range, prefix As String) As Double

    Dim result As Double
    Dim strVal As String
    Dim i As Integer
    Dim objRegExp As Object

   Set objRegExp = CreateObject("vbscript.regexp")
   With objRegExp
        .IgnoreCase = True
        .MultiLine = False
        .Pattern = "^[" + prefix + "]+[0-9]+(\,|\.)?[0-9]?$"
        .Global = True
    End With

    For i = 1 To Data.Rows.Count
        Debug.Print Data.Cells(i, 1)
        If objRegExp.Test(Data.Cells(i, 1)) = True Then
            strVal = Replace(Data.Cells(i, 1), prefix, "")
            Debug.Print strVal
            strVal = Trim(Replace(strVal, ",", "."))
            Debug.Print strVal
            result = result + CDbl(strVal)
        End If
    Next i

    SUM_PREFIX = result
End Function

Thanks for help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:33:59+00:00Added an answer on June 10, 2026 at 2:33 am

    CDbl is locale-aware, so check if your Replace is correct (for example, in my locale, I have to replace “.” by “,” in order for it to work).
    If you don’t want to rely on locale-aware code, use Val instead of CDbl because Val only recognizes “.” as a valid decimal separator regardless of locale.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try create a map for open ~/.vimrc, but open the ~/.vimrc only when
I want to try create something like Zend's Server Pagecache. What I want to
I try to create something, where you can drop different things on it, like
I try to create a new file inside a JSP and try to save
I'm try to create a new list object. I set the new object to
Whenever I try to edit existing or create new distribution provisioning profile on iOS
I try to create styles with first-child and last-child items but I encountered a
I have a function like this public void GetTablesWithUpperCaseName() { SqlConnectionStringBuilder objConnectionString = new
I want to Create a new User using Custom Membership Provider but I don't
I'm having trouble when I try to create a new object in ExtJS. First

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.