+ Reply to Thread
Results 1 to 10 of 10

Combine vba codes

Hybrid View

  1. #1
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine vba codes

    Replace that one macro with these two, the second Function is used by the first to properly clean out any hidden junk.

    Option Explicit
    
    Sub SplitSpecial()
    Dim SplitRNG As Range, StrSplit As Range
    Dim SplitArr As Variant, SplitBuf As String
    Dim SplitItem As Long, Codes As Long, Cnt As Long
    Application.ScreenUpdating = False
    
    Set SplitRNG = Range("A2:A" & Rows.Count).SpecialCells(xlCellTypeConstants)
    
        For Each StrSplit In SplitRNG
            SplitArr = Split(CleanAll(StrSplit), " ")
            Cnt = 1
            For SplitItem = LBound(SplitArr) To UBound(SplitArr)
                If Len(SplitArr(SplitItem)) <> 7 Then
                    SplitBuf = SplitBuf & " " & SplitArr(SplitItem)
                Else
                    StrSplit = Trim(SplitBuf)
                    SplitBuf = ""
                    For Codes = SplitItem To UBound(SplitArr)
                        StrSplit.Offset(0, Cnt) = SplitArr(Codes)
                        Cnt = Cnt + 1
                    Next Codes
                    Exit For
                End If
            Next SplitItem
        Next StrSplit
        
    Application.ScreenUpdating = True
    End Sub
    
    Function CleanAll(ByVal Txt As String) As String
    Dim X As Long     'Code base by Rick Rothstein (MVP - Excel)
        
        For X = 1 To Len(Txt)
            If Mid(Txt, X, 1) Like "*[!A-Za-z0-9 ]*" Then Mid(Txt, X, 1) = Chr(1) ' Leave only numbers, letters and spaces
        Next
    
    CleanAll = Replace(Txt, Chr(1), "")
    End Function
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  2. #2
    Registered User
    Join Date
    04-19-2010
    Location
    dublin, ireland
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Combine vba codes

    Quote Originally Posted by JBeaucaire View Post
    Replace that one macro with these two, the second Function is used by the first to properly clean out any hidden junk.
    Because all this is new to me I have what is probably a very dumb question

    I copied and pasted the original macro into excel so do i just copy and paste these two over the original or do i need to save the two new macros in separate files?

    Thanks

  3. #3
    Registered User
    Join Date
    04-19-2010
    Location
    dublin, ireland
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Combine vba codes

    Hi

    Is there a way to limit the CLEAN portion of this macro to just unprintable characters and extra spaces because some of the text has "-" and "@" that need to stay.

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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