+ Reply to Thread
Results 1 to 6 of 6

Merge two VBA codes in one

Hybrid View

  1. #1
    Registered User
    Join Date
    08-13-2023
    Location
    Algeria
    MS-Off Ver
    2007
    Posts
    2

    Merge two VBA codes in one

    I have these two VBA codes, to get the result, I have to put the following excel formula to do the trick : =CCPA(A1)&(MAJUSCULE(A1&MAJUSCULE(RIP(A1)))).
    I want to merge the two together in a function named for example : Account, so by just typing =Account(A1), it will give me the result obtained from the formula : =CCPA(A1)&(MAJUSCULE(A1&MAJUSCULE(RIP(A1))))

    The codes are :

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Our guidelines recommend code tags. I have added them for you this time because you are a new member. --6StringJazzer
        Function CCPA(X)
        Select Case Len(X)
        
        Case 0
        c1 = "00799999000000000"
        Case 1
        c1 = "00799999000000000"
        Case 2
        c1 = "0079999900000000"
        Case 3
        c1 = "007999990000000"
        Case 4
        c1 = "00799999000000"
        Case 5
        c1 = "0079999900000"
        Case 6
        c1 = "007999990000"
        Case 7
        c1 = "00799999000"
        Case 8
        c1 = "0079999900"
        Case 9
        c1 = "007999990"
        Case 10
        c1 = "00799999"
        
        End Select
        CCPA = c1
        
        End Function
        
        Public Function RIP(Cle_RIP As String) As String
        
        Cle_RIP = Right(Cle_RIP, 10)
        
        If Cle_RIP = "" Then
        Cle_RIP = 0
        End If
        RIP = Cle_RIP * 100
        RIP = RIP - 97 * Int(RIP / 97)
        RIP = RIP + 85
        
        If RIP < 97 Then
        RIP = RIP + 97
        Else
        RIP = RIP
        End If
        
        RIP = RIP - 97
        RIP = 97 - RIP
        
        If RIP < 10 Then
        RIP = "0" & RIP
        Else
        RIP = RIP
        End If
        End Function
    Last edited by 6StringJazzer; 08-13-2023 at 08:22 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: Post how to merge two VBA codes in one?

    There is no function in your code called MAJUSCULE. What is that?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Merge two VBA codes in one


    Hello six strings !

    MAJUSCULE is the local name of the Excel native UPPER worksheet function …

  4. #4
    Registered User
    Join Date
    08-13-2023
    Location
    Algeria
    MS-Off Ver
    2007
    Posts
    2

    Re: Merge two VBA codes in one

    forget about 'majuscule' it's not needed, I can do without it.
    so the formula will be:
    =CCPA(A1)&(A1&(RIP(A1)))

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: Merge two VBA codes in one

    Merci Marc L!

    Your original formula uses MAJUSCULE redundantly
    Original
    Formula: copy to clipboard
    =CCPA(A1)&(MAJUSCULE(A1&MAJUSCULE(RIP(A1))))

    Streamlined
    Formula: copy to clipboard
    =CCPA(A1)&(MAJUSCULE(A1&RIP(A1))


    So the code is:
    Public Function Account(S As String) As String
    
       Account = CCPA(A) & UCase(S & RIP(S))
    
    End Function
    UCase is the VBA function for uppercase, so it is not necessary to refer to the worksheet function in VBA.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: Merge two VBA codes in one

    Then you can just remove UCase from the code
    Public Function Account(S As String) As String
    
       Account = CCPA(A) & S & RIP(S)
    
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Merge two codes
    By juriemagic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2019, 07:06 AM
  2. How to Merge Two Worksheet_Change Codes
    By merveileuse in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2019, 04:56 AM
  3. merge vba codes together
    By pejabe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-11-2017, 08:58 AM
  4. Replies: 5
    Last Post: 01-27-2014, 12:20 PM
  5. [SOLVED] Merge 2 vba codes together
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-13-2013, 03:59 AM
  6. Merge codes
    By tofimoon4 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-18-2011, 06:22 AM
  7. merge with Word How can I get excel to mail merge zip codes plus 4 correctly?
    By Kathy at Sauder Feeds in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-30-2005, 07:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1