VBA learning methods

  • Hi


    I'm really unexperienced in VBA, and I'm wondering what's "the best way" to learn VBA from "scratch"?
    And is there any place that explains common words in VBA?
    For example "dim as". I find it in every macro, but i don't know what it means.


    I know how to record macros, but when i read about VBA in this forum it is on a diffrent level.


    Thanks!

  • Re: VBA learning methods


    Dim is used to declare the variable type. Lets say "Dim x as Integer" will tell the program, that values in x can only be whole positive numbers. You have more numeric types like Long, Double and so on. You also have boolean, which states true or false, string for... well strings and so on.


    I'm still a beginner when it comes to programming. I've had a bit of lessons of Visual Basic, which is a bit different from VBA at college, but most of my so far accumulated knowledge I had to get by myself. I did check a few tutorials on web, but they didn't really help much. You learn the most when you really try to do something, and if one way does not work, you try another one. If you still can't do it in the end, you can always ask for help here on forum, and learn from the code that others post. You can also read other posts here on forum that seem to be useful and interesting for you, and learn from that. Learning programming takes time, so don't rush it.


    And of course, if you see that another user of the forum posted a problem, and you think you might be able to solve it, try it. You will get better, trust me. And you will also help others at the same time.


    As for guides, I cant really recommend any, but from first look this one looks decent (http://www.excel-vba-easy.com/). But it probably wont help you much if you aren't using excel 2007 or 2010.

  • Re: VBA learning methods


    Probably the easiest way to learn would be to grab some code where you know what it does, step through it one line at a time, looking at what it's doing at every step. Learning to use things like the locals window will help a lot as well.

  • Re: VBA learning methods


    Stepping through code making sure you understand exactly what each statement does, and why, is probably the best way to quickly understand what's going on...


    Books can be useful, but you have no 'context' for the code/examples and they'll list all the keywords, properties, methods and events, but only in isolation. Seeing them used in working code is a much better option. Once you realise what an Event is, then you can go read up on more. Same for Methods and Properties...


    Books have one advantage, they can discuss 'proper' coding techniques and other things like how to handle errors, naming conventions, variable scope etc., so they should form part of your learning experience.


    Whether you read books/help text first or as needed is down to you and what you feel comfortable with.


    My opinion only.


    One little correction to jstrogues post though (sorry)...

    Quote

    that values in x can only be whole positive numbers


    From the Help files:


    Quote

    Integer variables are stored as 16-bit (2-byte) numbers ranging in value from -32,768 to 32,767

  • Re: VBA learning methods


    Make sure that you know basic Excel pretty thoroughly before attempting VBA. It's amazing how many people ask for help with a VBA solution that Excel has a standard feature for.

  • Re: VBA learning methods


    Heh cytop thx for correction :D I forgot to mention the range for the data types :D Types with smaller range use less memory, but will sometimes not be big enough. For example excel 2003 allows about 65k rows, and integer can only use 32k.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!