How to use Regular Expressions with Excel VBA (Part 1)

Поділитися
Вставка
  • Опубліковано 8 січ 2025

КОМЕНТАРІ • 95

  • @mikhailk5690
    @mikhailk5690 5 років тому +11

    This was a great help, thank you for this video! I am using VBA for 15 years but every time I find something new for me. I truly enjoy watching your tutorials!

  • @szilagyigabor3013
    @szilagyigabor3013 5 років тому +4

    For Each text In arr
    If regEx.Test(text) = True Then
    Set mc = regEx.Execute(text)
    For I = 0 To mc.Count
    shNamesCells(row, I + 2).Value = mc(I)
    Next I
    End If
    Next text
    If you have names with multiple elements. Great coding!

  • @nelsonrioux5555
    @nelsonrioux5555 5 років тому +3

    Great subject, your voice, no music and good pace: perfect VBA video. Thank you

  • @WTC_2U
    @WTC_2U 5 років тому +2

    You have a knack for covering topics that I am truly "fuzzy" with. In this case, I have tinkered with "Like" but it never quite gave me what I thought it would, and I really didn't understand why (or, how/which tools I should be using). I do now. Also REALLY enjoy when you show how a single line of code can do what many more might do. That is, I could have accomplished several things you showed here, but in about 5x the number of lines. And this is why I don't/can't write code for a living :)

  • @LosoIAm
    @LosoIAm 2 роки тому

    If this video had been available when I first started my journey in VBA (back in 2001), I would have been a Jedi Master in VBA by now. I had lots of energy (and esp. the passion and patience) back then!
    I now call myself (or sometimes cheekily sign) "VBA Worrier" - not a typo, by the way.
    Awesome video, many thanks!

  • @GarryI449
    @GarryI449 5 років тому +3

    This stuff is amazing. I used to have a function that did a ton of search and replace on a massive list to generate logic for automation systems. It did the job, but literally took over-night to complete, and while it was operating, you couldn't use the PC. With a few tweaks after watching your RUN-1000 TIMES FASTER video, it completes now in the time it takes to get a coffee. I Have some more optimizing to do yet but thanks so much for this stuff, and your website!

    • @LosoIAm
      @LosoIAm 2 роки тому

      Yes, the "Run-1000 Times Faster" video is a game-changer (being an Access/VBA veteran but Excel/VBA newbie).
      Note: I have read that Excel loads a workbook into RAM and this could cause performance issues.
      Sadly, I don't work with Excel; I am just trawling UA-cam (or the Internet) for stuff like this video to expand my knowledge/skill sets.

  • @glennlangford5897
    @glennlangford5897 5 років тому +3

    Thanks Paul, brilliant explanation, looking forward to Part 2

  • @houstonvanhoy2198
    @houstonvanhoy2198 3 роки тому +2

    Terrific, as usual. Thank you, Sir Paul!

  • @LosoIAm
    @LosoIAm 2 роки тому

    The techniques at your website "were" (probably) not available anywhere else - they are now, thanks to all your hard work and kindness!

  • @philipmcdonnell7168
    @philipmcdonnell7168 5 років тому +2

    Normally, even if I’m stood on a stepladder, how I can use your training flies way over my head. This time, I can see possibilities! Not quite nailed where but the concept is definitely lurking at the back of my mind. I’m looking forward to the next instalment. 👍🏻

  • @hadibq
    @hadibq 2 роки тому

    Awesome Tutorial very clean steps!

  • @michalroesler
    @michalroesler 4 роки тому

    What a great Tutorial Sir. I've learnt so much. I'm turning on another video. Thank you.

  • @ricos1497
    @ricos1497 5 років тому +3

    Great tutorial. I love regex, but for some reason I always forget to utilise it. This is great timing, I'll break it out again on my next project to keep the syntax in my head

  • @RJYL
    @RJYL 2 роки тому

    Great explanation!

  • @a_pear
    @a_pear 5 років тому +1

    This was an excellent video. I've been following your UA-cam series pretty well and am happy to hear your website is such a good resource as well. I've been spreading the good word about you around the office with my Junior OR staff, but probably need to put some of these lessons into a brown bag to get their code skills sharpened up. Anywho, excellent video once again, keep up the good work.

  • @rakeshkumarmadella7955
    @rakeshkumarmadella7955 4 роки тому

    Your training is awesome

  • @KhalilYasser
    @KhalilYasser 5 років тому +3

    Thank you very much Paul. Awesome tutorial.

    • @Excelmacromastery
      @Excelmacromastery  5 років тому +1

      Thanks Yasser.

    • @KhalilYasser
      @KhalilYasser 5 років тому

      @@Excelmacromastery Is there article related to this topic?

    • @Excelmacromastery
      @Excelmacromastery  5 років тому +2

      Not yet but I plan to create some in the near future.

    • @KhalilYasser
      @KhalilYasser 5 років тому

      @@Excelmacromastery Thank you very much.

  • @maciejdolinski2603
    @maciejdolinski2603 5 років тому +1

    Great tutorial. Thank you, Paul!

  • @frenzyyyy7186
    @frenzyyyy7186 4 роки тому

    Very good explanation! Thanks for this I really need this tutorial. More power to you.

  • @LearningSpanishforbeginn-nu2jm

    Excellent video. Very very helpful with using Regex inside of Excel. Can you tell me how you would go about setting up an array for RegEx.Pattern so that I could write a script that will search through a text file and extract out multiple items and save them in various cells?

  • @iincitr
    @iincitr 5 років тому

    Amazing
    Again Thanks Paul for your clean speech, explanation, and demonstrations.

  • @davidunger7425
    @davidunger7425 5 років тому

    Great video Paul, looking forward to the sequel!

  • @richrobins5711
    @richrobins5711 5 років тому

    Thank you Paul! I used it in a project I had that was counting occurrences of several strings in a file! I was doing it that it had to use several passes on the file but with this I can do it all in 1 pass!

  • @frikduplessis3869
    @frikduplessis3869 5 років тому +1

    Brilliant again Paul

  • @myessaytutor
    @myessaytutor 5 років тому

    Great video, again. I'm looking forward to Part 2.

  • @ventjemazzel8822
    @ventjemazzel8822 5 років тому

    Very helpful indeed; thank you!

  • @velus7431
    @velus7431 3 місяці тому

    Thanks! Although I did not understand what is difference between 'like' clause and 'regex' syntax. Is the 'like' clause a limited subset of 'regex'?

  • @ventjemazzel8822
    @ventjemazzel8822 3 роки тому

    Awesome; thank you.

  • @itlife4555
    @itlife4555 2 роки тому

    before i learn it here, i thought Regex is very difficult, But after i learn your turtorial here, i found Regex very simple.....

  • @LosoIAm
    @LosoIAm 2 роки тому

    Great video - THANK YOU!
    A small note: although the dim statements do not get executed in the loop and moving them to above the loop will produce the same result as the original code.
    Question: do you know if declaring the variables inside the loop will cause the code to run slower?

  • @alreadydeadfunk
    @alreadydeadfunk 3 роки тому +1

    In case no one says in the comments below, you could also assign the object to vbscript.regexp using CreateObject function when declaring the object variable which allows you to use the same Regular Expression library. To be more precise, type in something like this 'Dim regexp As Object: Set regexp = CreateObject("vbscript.regexp")'

    • @Excelmacromastery
      @Excelmacromastery  3 роки тому +1

      That's Late Binding which is useful when releasing the software but the downside is that it doesnt' give access to Intellisense.

  • @kingpin11111
    @kingpin11111 4 роки тому

    At 12:37 you write "\d+" into your pattern to search for all the numbers. Can anyone please tell me, what does the "\d+" actually stands for? Is it some built-in expression in VBA for numbers? If so, then where can I found it in VBA help documentation (which topic name?). Are there other similar expressions? I have never seen that before. Thanks.

    • @Excelmacromastery
      @Excelmacromastery  4 роки тому +1

      Regular Expressions are not part of VBA. They are a separate library that is used by many languages. You can google Regular Expressions tutorial to find out how they work.

  • @vijaysahal4556
    @vijaysahal4556 3 роки тому

    nice sir 👍🏻👍🏻👍🏻💯💯💯

  • @ExcelVisual
    @ExcelVisual 5 років тому

    It is interesting. Thanks for the idea!

  • @houstonvanhoy7767
    @houstonvanhoy7767 3 роки тому +1

    I'll be reviewing this a couple of times after "Midsomer Murders" is over. 😊 R.I.P. Sykes. 😢

  • @grahamparker7729
    @grahamparker7729 5 років тому

    Nice one Paul 👍🏻

  • @apurvaumang3581
    @apurvaumang3581 4 роки тому

    I have a string which looks something like this 10x10 Hot Dog Bags, but the problem with the string is, it can sometimes have X in blocks sometimes small. It can have spaces between the X and numbers. Also it can have the numbers after the Alphabets in the string like Manchurian Candidate Sleeve Bag 19X 18. In addition to this the numbers are sometimes not evenly placed (i.e. trailing whitespaces and lastly it could look like this 10" X 9" Megadeath Sauce packet bag. How to build a pattern for this and loop through all records to get only the numbers i.e 10 in one column in excel and 9 in the other and so on.

  • @rrrprogram8667
    @rrrprogram8667 5 років тому

    Oh awesomeee Paul... But this content is not available in ur website right ???... can you make a video .. of half n hour may be...to elaborate on the mostly used algorithms in Regex .... ??

    • @Excelmacromastery
      @Excelmacromastery  5 років тому +1

      It's not on the website yet but I hope to add an article about this in the future. The next videos covers the basics of using RegEx expressions.

  • @johnnyc873
    @johnnyc873 5 років тому

    Nice explanation Paul. I was aware of them but never knew what they could be used for, they look perfect for parsing pathnames into the folders.
    Can they be used for control characters? We have a system that randomly inserts ascii 8 into fields in data dumps as separators and it would be handy to put the data into a collection using the ascii 8 as a delimiter

    • @serbach
      @serbach 5 років тому

      Johnny c,
      I think you mean ASCII 9 which is the TAB character. ASCII 8 is the BACKSPACE.
      Regular Expressions can search and replace tabs easily. The shorthand way of representing a TAB in a regular expression is \t. I use it all the time.
      By the way, the absolute best reference work for learning regular expressions is the one compiled by Jan Goyvaerts. Just search for his name on Google and you'll find his book and on-line tutorial.

    • @Excelmacromastery
      @Excelmacromastery  5 років тому

      Yes they can.

  • @rrrprogram4704
    @rrrprogram4704 5 років тому +1

    Hi paul.... if the macro code gets bigger and bigger .. how to you manage. Do u use GIT ???? is it even possible to use GIT with macro code ??

    • @ukaszbrzozowski2377
      @ukaszbrzozowski2377 5 років тому

      Bump :) Do you plan to make video about that? :)

    • @Excelmacromastery
      @Excelmacromastery  5 років тому

      You can use any version control software with the code including Git.
      The problem with VBA is that you have to export the modules from Excel to files first. You can use third party software to export all your files in one go or you can write your own code to do it. It's a bit messy to say the least.
      -Paul

  • @houstonvanhoy7767
    @houstonvanhoy7767 3 роки тому +1

    How to use Regular Expressions with Excel VBA (Part 2): ua-cam.com/video/MKDC03t407I/v-deo.html

  • @jgirard1970
    @jgirard1970 5 років тому

    Once again, nice video. I want to ask. What IDE are you using? Yours looks different than mine in Excel 2016.

    • @michaelk8642
      @michaelk8642 5 років тому +1

      The VBA IDE hasn't changed in years. Paul has most likely customized his toolbars and views.

    • @Excelmacromastery
      @Excelmacromastery  5 років тому

      Yes - it's 2016 but as Michael said the IDE hasn't changed in years. It probably looks different because the Immediate window is floating and the project and property windows are closed.

  • @rakeshkumarmadella7955
    @rakeshkumarmadella7955 4 роки тому +1

    Hello paul,

  • @PerFeldvoss
    @PerFeldvoss 2 роки тому

    Great, but why would you write \d+ in the pattern?

  • @rakeshkumarmadella7955
    @rakeshkumarmadella7955 4 роки тому +1

    How r ? actually I want to purchase your handbook.. but I am from India it's 350dollars.. in India rs 21,000 it's a very huge amount and I can't afford is there any other alternative where I can purchase ur handbook

  • @not.an.operator
    @not.an.operator 3 роки тому

    I only see VBScript 1.0 in my references. Anyone know how to get 5.5 to show up?

  • @tobiewaldeck7105
    @tobiewaldeck7105 4 роки тому

    I keep getting Method 'Range' of object' -Worksheet' failed or Global failed at "arr = shNames" even though code is the same.

  • @harrysherman8166
    @harrysherman8166 3 роки тому

    WHY IS Microsoft VBScript Regular Expression 5.5 NOT IN MY REFERENCE LIBRARY PLEASE HELP

  • @cocococo8147
    @cocococo8147 5 років тому

    Video 7:48, How do you delete the code?

  • @hemant0088
    @hemant0088 5 років тому +1

    Hi, you have given great demonstration about Reg Ex in VBA.
    However, I am trying to find how to connect AS400 terminals using Excel VBA.
    Could you please assist me?

    • @KhalilYasser
      @KhalilYasser 5 років тому

      @
      hemant Kawalkar
      Can you give more details and put some of the expected output?

    • @hemant0088
      @hemant0088 5 років тому

      @@KhalilYasser AS400 usually comes only in company's. I can give you few screenshots or what it is ? So far I know we need to use some dll. But I don't know which one or where to start.

  • @irajatsolanki
    @irajatsolanki 5 років тому

    How to create a function based on=REGEXREPLACE(A1,"\D+","") regex
    replace like Google sheets

  • @tughanozsezer9332
    @tughanozsezer9332 5 років тому

    👍

  • @joaocustodio2094
    @joaocustodio2094 5 років тому

    Paul,,

  • @debjitsarkar2651
    @debjitsarkar2651 5 років тому

    Sir please tell me
    "WHY SAME VBA CORD RUN FIRST SOME TIME & SLOW SOME TIME.SAME CORD IN SAME EXCEL FILE .PLEASE REPLY.HOW TO SOLVE THIS PROBLEM?

  • @rheitzman
    @rheitzman 5 років тому

    A huge downside to RegEx is that code containing them is not maintainable. If you are working on throw away code they are fine.

    • @Excelmacromastery
      @Excelmacromastery  5 років тому

      Why is the code not maintainable??

    • @felixrode1290
      @felixrode1290 5 років тому

      @@Excelmacromastery I was wondering that too. Great video Paul, very useful not just for Excel but great potential for MS Access too. As a general rule I would use late binding to ensure the highest level of compatibility - any thoughts on that ?

  • @donepearce
    @donepearce 5 років тому

    Please try to kill some confusion. Please don't choose variable names that are almost identical to the related function name. Go for something totally different, so don't call your array ARR, call it John, shoelace or Buffalo. You remind me a little of my maths teacher at school. He would illustrate a problem and end up with an equation, but he always chose his values so almost everything cancelled top and bottom. What remained was great for him, but explained nothing about the process.

    • @nordicdust
      @nordicdust 5 років тому

      I am pretty sure that it is common practice and makes sence. Dim ARR As ARRAY, Dim VAR As VARIANT, Dim COL As COLUMN

    • @donepearce
      @donepearce 5 років тому

      @@nordicdust One man's common sense is another man's failure of imagination. Variable names should always be about the content of the variable, never about the structure of the programming language.

  • @baruchpale
    @baruchpale 5 років тому +1

    Very useful. Thank you Paul.

  • @joaocustodio2094
    @joaocustodio2094 5 років тому

    Very very useful. Thanks very much Paul.