Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. VBA in Excel

VBA in Excel

Scheduled Pinned Locked Moved The Lounge
javascriptlinuxquestioncareer
26 Posts 17 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Chris Maunder

    I decided that, instead of manually categorising a bunch of values in a spreadsheet I'd write a simple VBA method that would do the hard work for me. After all, doing it manually would take about an hour. Writing a bit of VBA couldn't take more than... well, I think I'm on hour 5 at this point. It's been a long time since I've done VBScript, but even VBScript was generally fairly sensible. VBA? I can't believe it's 2020 and VBA is pretty much the only scripting option available in Excel. Sure, you can write add-ins using Javascript and in-cell formula using Javscript, but no Javascript scripting. No constructor, serious hassles passing user defined types between methods, a limit to the number of times you can use line continuation in a row, the awful experience overall. I can't believe how much of the world lives and breathes this stuff. (but of course I'm going to bash my way through it instead of just getting the job done the old fashioned way)

    cheers Chris Maunder

    Richard DeemingR Offline
    Richard DeemingR Offline
    Richard Deeming
    wrote on last edited by
    #4

    Obligatory XKCD: Automation[^] :-D And yes, VBA, the red-haired illegitimate step-child of VB4, still sucks big fat hairy ones. At this point, I think it's too late for MS to fix it. Maybe it's time for the Ripley option[^]?


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

    C 1 Reply Last reply
    0
    • Richard DeemingR Richard Deeming

      Obligatory XKCD: Automation[^] :-D And yes, VBA, the red-haired illegitimate step-child of VB4, still sucks big fat hairy ones. At this point, I think it's too late for MS to fix it. Maybe it's time for the Ripley option[^]?


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      C Offline
      C Offline
      Chris Maunder
      wrote on last edited by
      #5

      And I'll Obligatory right back at you: [xkcd: Is It Worth the Time?](https://xkcd.com/1205/)

      cheers Chris Maunder

      Richard DeemingR M 2 Replies Last reply
      0
      • C Chris Maunder

        And I'll Obligatory right back at you: [xkcd: Is It Worth the Time?](https://xkcd.com/1205/)

        cheers Chris Maunder

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #6

        But did you factor in the time you spend finding the chart to look up what you save? :)


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • C Chris Maunder

          I decided that, instead of manually categorising a bunch of values in a spreadsheet I'd write a simple VBA method that would do the hard work for me. After all, doing it manually would take about an hour. Writing a bit of VBA couldn't take more than... well, I think I'm on hour 5 at this point. It's been a long time since I've done VBScript, but even VBScript was generally fairly sensible. VBA? I can't believe it's 2020 and VBA is pretty much the only scripting option available in Excel. Sure, you can write add-ins using Javascript and in-cell formula using Javscript, but no Javascript scripting. No constructor, serious hassles passing user defined types between methods, a limit to the number of times you can use line continuation in a row, the awful experience overall. I can't believe how much of the world lives and breathes this stuff. (but of course I'm going to bash my way through it instead of just getting the job done the old fashioned way)

          cheers Chris Maunder

          Mike HankeyM Offline
          Mike HankeyM Offline
          Mike Hankey
          wrote on last edited by
          #7

          After the first hour, the time it would have taken to do it the old fashioned way, it becomes a matter of pride!

          Monday starts Diarrhea awareness week, runs until Friday! JaxCoder.com

          1 Reply Last reply
          0
          • C Chris Maunder

            And I'll Obligatory right back at you: [xkcd: Is It Worth the Time?](https://xkcd.com/1205/)

            cheers Chris Maunder

            M Offline
            M Offline
            Mark_Wallace
            wrote on last edited by
            #8

            Ah, but once it's automated, how much time do you save explaining (and re-explaining) how to use it to non-techies?

            I wanna be a eunuchs developer! Pass me a bread knife!

            1 Reply Last reply
            0
            • C Chris Maunder

              I decided that, instead of manually categorising a bunch of values in a spreadsheet I'd write a simple VBA method that would do the hard work for me. After all, doing it manually would take about an hour. Writing a bit of VBA couldn't take more than... well, I think I'm on hour 5 at this point. It's been a long time since I've done VBScript, but even VBScript was generally fairly sensible. VBA? I can't believe it's 2020 and VBA is pretty much the only scripting option available in Excel. Sure, you can write add-ins using Javascript and in-cell formula using Javscript, but no Javascript scripting. No constructor, serious hassles passing user defined types between methods, a limit to the number of times you can use line continuation in a row, the awful experience overall. I can't believe how much of the world lives and breathes this stuff. (but of course I'm going to bash my way through it instead of just getting the job done the old fashioned way)

              cheers Chris Maunder

              J Offline
              J Offline
              Jorgen Andersson
              wrote on last edited by
              #9

              I guess we need something like Webassembly Excelassembly. Then again, having fiddled with the file format I have to admit I'm quite for the Ripley option.

              Wrong is evil and must be defeated. - Jeff Ello

              1 Reply Last reply
              0
              • C Chris Maunder

                I decided that, instead of manually categorising a bunch of values in a spreadsheet I'd write a simple VBA method that would do the hard work for me. After all, doing it manually would take about an hour. Writing a bit of VBA couldn't take more than... well, I think I'm on hour 5 at this point. It's been a long time since I've done VBScript, but even VBScript was generally fairly sensible. VBA? I can't believe it's 2020 and VBA is pretty much the only scripting option available in Excel. Sure, you can write add-ins using Javascript and in-cell formula using Javscript, but no Javascript scripting. No constructor, serious hassles passing user defined types between methods, a limit to the number of times you can use line continuation in a row, the awful experience overall. I can't believe how much of the world lives and breathes this stuff. (but of course I'm going to bash my way through it instead of just getting the job done the old fashioned way)

                cheers Chris Maunder

                J Offline
                J Offline
                JurgenP3
                wrote on last edited by
                #10

                In the Microsoft Tech community, there is a feature request to add support for Python as an Excel scripting language : python for excel application scripting - Microsoft Tech Community - 66113[^]

                C 1 Reply Last reply
                0
                • C Chris Maunder

                  I decided that, instead of manually categorising a bunch of values in a spreadsheet I'd write a simple VBA method that would do the hard work for me. After all, doing it manually would take about an hour. Writing a bit of VBA couldn't take more than... well, I think I'm on hour 5 at this point. It's been a long time since I've done VBScript, but even VBScript was generally fairly sensible. VBA? I can't believe it's 2020 and VBA is pretty much the only scripting option available in Excel. Sure, you can write add-ins using Javascript and in-cell formula using Javscript, but no Javascript scripting. No constructor, serious hassles passing user defined types between methods, a limit to the number of times you can use line continuation in a row, the awful experience overall. I can't believe how much of the world lives and breathes this stuff. (but of course I'm going to bash my way through it instead of just getting the job done the old fashioned way)

                  cheers Chris Maunder

                  D Offline
                  D Offline
                  DJ van Wyk
                  wrote on last edited by
                  #11

                  And to make things even "better"; the IDE hasn't been updated in more than 20 years (as far as I know).

                  My plan is to live forever ... so far so good

                  U Z 2 Replies Last reply
                  0
                  • D DJ van Wyk

                    And to make things even "better"; the IDE hasn't been updated in more than 20 years (as far as I know).

                    My plan is to live forever ... so far so good

                    U Offline
                    U Offline
                    User 12164033
                    wrote on last edited by
                    #12

                    don't moan dear fellow devs, have e.g. a look at Write Office COM add-in, smart tag, RTD server in Visual Studio .NET, VSTO, VCL[^] or, not my cup-of-tea, Office add-in Yeoman Generator demonstration - YouTube[^]

                    M 1 Reply Last reply
                    0
                    • D DJ van Wyk

                      And to make things even "better"; the IDE hasn't been updated in more than 20 years (as far as I know).

                      My plan is to live forever ... so far so good

                      Z Offline
                      Z Offline
                      ZevSpitz
                      wrote on last edited by
                      #13

                      Have you seen Rubberduck, an addin which uses ANTLR to parse VBA and add more features? Also, there's a proposal on Rubberduck's repo to create a Language Server Protocol implementation for VBA; this would allow any LSP-supporting editor, such as VS Code, to work with VBA.

                      1 Reply Last reply
                      0
                      • U User 12164033

                        don't moan dear fellow devs, have e.g. a look at Write Office COM add-in, smart tag, RTD server in Visual Studio .NET, VSTO, VCL[^] or, not my cup-of-tea, Office add-in Yeoman Generator demonstration - YouTube[^]

                        M Offline
                        M Offline
                        Member 12364390
                        wrote on last edited by
                        #14

                        Good Tips '489 ! Writing add-ins seems to be the only way to automate Office 365. It is becoming the corporate office platform in a lot of places so indeed MS has done a Ripley on us corporate software developers. If you do have to work in VBA -there are many toolsets to help write and maintain good code - MZ tools is my preference but Rubberduck · GitHub[^] looks good too. Its an old but stable IDE -little Intellisense, no autocompletion - but that only helps the coding - not the thinking! Export all your code modules, forms, spreadsheet content, formulae, formats to text files. Then you can do version control in mercurial, and inspection in Npp Merging is an issue but you can see what changed and revert or branch.

                        T 1 Reply Last reply
                        0
                        • M Member 12364390

                          Good Tips '489 ! Writing add-ins seems to be the only way to automate Office 365. It is becoming the corporate office platform in a lot of places so indeed MS has done a Ripley on us corporate software developers. If you do have to work in VBA -there are many toolsets to help write and maintain good code - MZ tools is my preference but Rubberduck · GitHub[^] looks good too. Its an old but stable IDE -little Intellisense, no autocompletion - but that only helps the coding - not the thinking! Export all your code modules, forms, spreadsheet content, formulae, formats to text files. Then you can do version control in mercurial, and inspection in Npp Merging is an issue but you can see what changed and revert or branch.

                          T Offline
                          T Offline
                          thewazz
                          wrote on last edited by
                          #15

                          Member 12364390 wrote:

                          little Intellisense, no autocompletion

                          Wish I'd found this sooner:

                          Ctrl+j

                          1 Reply Last reply
                          0
                          • J JurgenP3

                            In the Microsoft Tech community, there is a feature request to add support for Python as an Excel scripting language : python for excel application scripting - Microsoft Tech Community - 66113[^]

                            C Offline
                            C Offline
                            Chris Maunder
                            wrote on last edited by
                            #16

                            :doh:

                            cheers Chris Maunder

                            1 Reply Last reply
                            0
                            • C Chris Maunder

                              I decided that, instead of manually categorising a bunch of values in a spreadsheet I'd write a simple VBA method that would do the hard work for me. After all, doing it manually would take about an hour. Writing a bit of VBA couldn't take more than... well, I think I'm on hour 5 at this point. It's been a long time since I've done VBScript, but even VBScript was generally fairly sensible. VBA? I can't believe it's 2020 and VBA is pretty much the only scripting option available in Excel. Sure, you can write add-ins using Javascript and in-cell formula using Javscript, but no Javascript scripting. No constructor, serious hassles passing user defined types between methods, a limit to the number of times you can use line continuation in a row, the awful experience overall. I can't believe how much of the world lives and breathes this stuff. (but of course I'm going to bash my way through it instead of just getting the job done the old fashioned way)

                              cheers Chris Maunder

                              K Offline
                              K Offline
                              Kirk 10389821
                              wrote on last edited by
                              #17

                              Why not generalize it and write a plugin? Then you can play DLL-Hell with every machine that needs it. Of course, if it only modifies and fixes the cells for you, then one machine is all it will take. Pity me, I once opened the xlsx file and looked at modifying the cells directly. I backed down, and did it the old fashioned way!

                              1 Reply Last reply
                              0
                              • C Chris Maunder

                                I decided that, instead of manually categorising a bunch of values in a spreadsheet I'd write a simple VBA method that would do the hard work for me. After all, doing it manually would take about an hour. Writing a bit of VBA couldn't take more than... well, I think I'm on hour 5 at this point. It's been a long time since I've done VBScript, but even VBScript was generally fairly sensible. VBA? I can't believe it's 2020 and VBA is pretty much the only scripting option available in Excel. Sure, you can write add-ins using Javascript and in-cell formula using Javscript, but no Javascript scripting. No constructor, serious hassles passing user defined types between methods, a limit to the number of times you can use line continuation in a row, the awful experience overall. I can't believe how much of the world lives and breathes this stuff. (but of course I'm going to bash my way through it instead of just getting the job done the old fashioned way)

                                cheers Chris Maunder

                                P Offline
                                P Offline
                                Peter R Fletcher
                                wrote on last edited by
                                #18

                                As a fairly serious Access programmer, I feel your pain! The one complaint that I don't endorse, though, is about the limit on consecutive line continuations, which I must say I have never run into. On the whole, I feel that if you have to continue a logical line over more than a couple of printed lines, you should break up the logic, since it is likely to be difficult to understand if/when you come back to it later, let alone by anyone else!

                                C 1 Reply Last reply
                                0
                                • P Peter R Fletcher

                                  As a fairly serious Access programmer, I feel your pain! The one complaint that I don't endorse, though, is about the limit on consecutive line continuations, which I must say I have never run into. On the whole, I feel that if you have to continue a logical line over more than a couple of printed lines, you should break up the logic, since it is likely to be difficult to understand if/when you come back to it later, let alone by anyone else!

                                  C Offline
                                  C Offline
                                  Chris Maunder
                                  wrote on last edited by
                                  #19

                                  With regards to the line continuation issues, what I'm trying to do is create a an array (an ever growing array!) of terms that can be used to categorise an item. eg

                                  items = Array("item1", _
                                  "item2", _

                                            ...
                                  
                                            "itemN")
                                  

                                  N, for me, has grown beyond the limits of what VBA likes. What I probably should do is just enter the terms in the spreadsheet somewhere and have the method reference the values in those cells rather than hard coding. I've well and truly burned through the 1hr I budgeted on this one

                                  cheers Chris Maunder

                                  P O 2 Replies Last reply
                                  0
                                  • C Chris Maunder

                                    With regards to the line continuation issues, what I'm trying to do is create a an array (an ever growing array!) of terms that can be used to categorise an item. eg

                                    items = Array("item1", _
                                    "item2", _

                                              ...
                                    
                                              "itemN")
                                    

                                    N, for me, has grown beyond the limits of what VBA likes. What I probably should do is just enter the terms in the spreadsheet somewhere and have the method reference the values in those cells rather than hard coding. I've well and truly burned through the 1hr I budgeted on this one

                                    cheers Chris Maunder

                                    P Offline
                                    P Offline
                                    Peter R Fletcher
                                    wrote on last edited by
                                    #20

                                    Understandability isn't an issue, then, but I think you are right about what you should do. When I have the same sort of issue in Access VBA, I generally create a new Table (if the 'array' is likely to be needed again) or Recordset (if it isn't), which is pretty much the Access equivalent of entering the terms on the spreadsheet in Excel.

                                    O 1 Reply Last reply
                                    0
                                    • C Chris Maunder

                                      With regards to the line continuation issues, what I'm trying to do is create a an array (an ever growing array!) of terms that can be used to categorise an item. eg

                                      items = Array("item1", _
                                      "item2", _

                                                ...
                                      
                                                "itemN")
                                      

                                      N, for me, has grown beyond the limits of what VBA likes. What I probably should do is just enter the terms in the spreadsheet somewhere and have the method reference the values in those cells rather than hard coding. I've well and truly burned through the 1hr I budgeted on this one

                                      cheers Chris Maunder

                                      O Offline
                                      O Offline
                                      OldBogey
                                      wrote on last edited by
                                      #21

                                      Yet another case of someone using excel as a quasi database. It should have just been done in Access in the first place. I, too, have done a lot in Access VBA - easy when you know how. The problem I've found in Excel VBA is that they named most 'things' differently. I haven't done any VBA for Winword, but the same issues probably arise. No doubt that different teams did the initial design for each program.

                                      C 1 Reply Last reply
                                      0
                                      • P Peter R Fletcher

                                        Understandability isn't an issue, then, but I think you are right about what you should do. When I have the same sort of issue in Access VBA, I generally create a new Table (if the 'array' is likely to be needed again) or Recordset (if it isn't), which is pretty much the Access equivalent of entering the terms on the spreadsheet in Excel.

                                        O Offline
                                        O Offline
                                        OldBogey
                                        wrote on last edited by
                                        #22

                                        Understanding the principles of relational database design is a first step.

                                        1 Reply Last reply
                                        0
                                        • O OldBogey

                                          Yet another case of someone using excel as a quasi database. It should have just been done in Access in the first place. I, too, have done a lot in Access VBA - easy when you know how. The problem I've found in Excel VBA is that they named most 'things' differently. I haven't done any VBA for Winword, but the same issues probably arise. No doubt that different teams did the initial design for each program.

                                          C Offline
                                          C Offline
                                          Chris Maunder
                                          wrote on last edited by
                                          #23

                                          Sorry, but it shouldn't have been done in Access in the first place. This is a spreadsheet I'm working on, and it includes text, formatting, multiple worksheets and it needs to be approachable and usable by a non-developer. The categorisation part is a minor, minor part of this. I'm not a fan of changing the problem to suit the tools. I choose the tools to suit the problem.

                                          cheers Chris Maunder

                                          O 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups