Follow-up... custom delimiter (text to column)

Experts:

In a previous post (http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28490280.html ), I've was provided an excellent solution for developing custom-delimiter formulas/functions.

Upon receiving the first (excellent) solution, I closed the question and awarded points to expert (Glenn).
Afterwards, expert (aikimark) offered yet another solution... which is also very efficient.

At this time, I'd like to learn more about the regex pattern so that a) I can make sense of its logic and b) modify it in the event additional pattern recognition is required.

Thank you in advance for any "comments" you could offer on aikimark's VBA.

EEH
ExpExchHelpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
I assume you are playing with http:Q_28490280.html#a40239901
Correct me if I'm wrong.

Here is a copy of the code, so we don't have to switch between threads
Sub Q_28490280()
    Dim oRE As Object
    Dim oMatches As Object
    Dim oM As Object
    Dim rng As Range
    Dim rngCell As Range
    
    Set rng = ActiveSheet.Range(ActiveSheet.Range("A2"), ActiveSheet.Range("A2").End(xlDown))
    
    Set oRE = CreateObject("vbscript.regexp")
    oRE.Global = False
    oRE.Pattern = "(.*?) (U[A-Z]{1,3}[^<]*)(<[^>]+>)"
    'NOTE: uncomment the following statement for best performance
    'Application.ScreenUpdating = False
    For Each rngCell In rng
        If oRE.test(rngCell.Value) Then
            Set oMatches = oRE.Execute(rngCell.Value)
            With oMatches(0)
                rngCell.Offset(0, 1).Value = .submatches(0)
                rngCell.Offset(0, 2).Value = .submatches(1)
                rngCell.Offset(0, 3).Value = .submatches(2)
                'Debug.Print .submatches(0), .submatches(1), .submatches(2)
            End With
        End If
    Next
    Application.ScreenUpdating = True
End Sub

Open in new window

Firstly, you should familiarize yourself with regular expressions in the VBA environment.  A good start is this article: http:A_1336.html

The Pattern:
(.*?) (U[A-Z]{1,3}[^<]*)(<[^>]+>)
"(.*?)" - capture zero or more characters, but don't be greedy
" " - there will be a space character, but don't capture it
"(U[A-Z]{1,3}[^<]*)" - capture a string that starts with an upper case U and is followed by 1-3 upper case letters.  That will be followed by zero or more characters that are not a less than character, <
"(<[^>]+>)" - capture a string that begins with a less than character, <, followed by one or more characters that are not a greater than character, >, terminated with a greater than character.

Thus, there are three capture groups which result in three submatches items.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aikimarkCommented:
You only provided three data examples, which had been sanitized and your data description was not detailed enough that I could have posted a more refined regex pattern.  We can use this thread for that refinement.

I think this approach is better than trying to type all the possible combinations of delimiters for the formula solution you accepted in the prior related thread
0
ExpExchHelpAuthor Commented:
aikimark:

Thank you for the prompt response and additional information.

As suggested, allow me to familiarize myself with the article posted on http:A_1336.html.

MTF,
EEH
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

ExpExchHelpAuthor Commented:
aikimark:

As part of Patrick's posting, he provided an XLS with example solution.

I've downloaded the file twice... and twice it results in errors.    Do you know what might be causing the VBA errors?   Please see attached Patrick's XLS as well as two screenshots (errors that I run into when opening the spreadsheet).

EEH
Regular-Expressions-Examples.xls
Capture.JPG
Capture2.JPG
0
aikimarkCommented:
I can open the workbook.  Does it fail on open or when you have tried to do something in particular?

Unfortunately, Patrick is out of the country now.

Did you get some warning messages on open?  Did you click OK (trust this content)
0
ExpExchHelpAuthor Commented:
It pretty much freezes (resulting in error as shown in snaphot 1).    Once I attempt closing it (which takes a moment), I then see the VBA error message (400)... snapshot 2.

I'll try on another machine.

Thanks,
EEH
0
aikimarkCommented:
are you on a 64-bit version of Office?
0
ExpExchHelpAuthor Commented:
Yes... 64-bit OS (Windows 7).
0
ExpExchHelpAuthor Commented:
Not sure abou6 64-bit version for Office.   We're using Office 2010.
0
aikimarkCommented:
It should show up in the Help About.

You might try opening the xls file without macros enabled and save it as an xlsm format, which supports macros.
0
aikimarkCommented:
If you have Excel2003 with the compatibility pack installed, you should be able to open the xls file and save it as an xlsm file.
0
Glenn RayExcel VBA DeveloperCommented:
@aikimark..I tried opening the Patrick's example file and received the same errors - Excel forced to restart.  On Excel restart I receive the following:
Excel Error

I'm running Office 2010 32-bit (Excel 14.0.7128.5000) on Windows 7 Enterprise SP1 64-bit.  

-Glenn
0
aikimarkCommented:
See if the attached xlsm file behaves itself
Regular-Expressions-Examples.xlsm
0
Glenn RayExcel VBA DeveloperCommented:
Yep! Works like a charm (great functions).

You might want to let Patrick know so the file in the article can be updated.

Thanks,
-Glenn
0
ExpExchHelpAuthor Commented:
aikimark -- completely agree with Glenn.   The xlsm works great!  

I'll continue to review the functions.

EEH
0
ExpExchHelpAuthor Commented:
Excellent info!!!!
0
aikimarkCommented:
Did you have to tweak the pattern I posted?

Are you now a regular expression enthusiast?
0
ExpExchHelpAuthor Commented:
No -- didn't have to tweak your (excellent) solution.   :)
Yes -- I'm converted now... 'will have to learn much more to create own patterns though.   :)

Again, thank you for your help.
0
aikimarkCommented:
In your original sample data, all the organization names seemed to be terminated with a "(XX)" string.  If that parenthetical string exists for all your records, no matter the length of that string, you can trim the parsed organization name with a tweaked pattern that terminates the organization name with that pattern.
0
ExpExchHelpAuthor Commented:
aikimark -- thanks for the additional info... I'll check it out.   ;)

EEH
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.