Results 1 to 2 of 2

Thread: Self-Learn Excel VBA

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Self-Learn Excel VBA

    Hi,

    I am new to VBA macros. I know a bit of Excel, but would like to learn VBA. I have a few PDFs from the internet, but it seems a little too advanced. Please suggest how can I learn VBA.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Hi Meghna,

    Welcome to ExcelFox community.

    Start recording macros, and perform actions in the excel spreadsheet.The macro recorder will record macro. A lot of the lines may be superfluous, but you'll get a general perspective of how macro works. Slowly, you'll learn to read and differentiate between lines that actually do the task, and the superfluous ones.

    As an example, I recorded my action. I typed in a few lines is what I did.
    Code:
    Sub Macro1()
    
        Range("B3").Select
        ActiveCell.FormulaR1C1 = _
            "I am recording a macro to understand what the macro recorder records."
        Range("B4").Select
        ActiveCell.FormulaR1C1 = _
            "OK, I'll now write another text. I wonder what the macro recorder would have recorded now."
        Range("B5").Select
        ActiveCell.FormulaR1C1 = "Oh well, been years since I did something like this."
        Range("D3").Select
        ActiveCell.FormulaR1C1 = _
            "Ok, just for the sake of it, I've scrolled to the right a bit and moved up to cell D3, to type this text."
        Range("D4").Select
       
    End Sub
    Now, a lot of those lines are superfluous. I could rewrite it like so.
    Code:
    Sub Macro2()
    
        Range("B3").Resize(3, 1).Value = _
        Array("I am recording a macro to understand what the macro recorder records.", _
        "OK, I'll now write another text. I wonder what the macro recorder would have recorded now.", _
        "Oh well, been years since I did something like this.")
        Range("D3").Value = "Ok, just for the sake of it, I've scrolled to the right a bit and moved up to cell D3, to type this text."
       
    End Sub
    So you see, just record macro, and eventually, the macro will teach you a lot of the syntax. Based on your understanding of how things work, you can then reduce the lines of code as I have did above.

    Note: Since Excel 2007 Chart actions are not recorded, and I can assure you a lot of others aren't (for reasons I do not want to pretend I know), if you want to go the learning path by recording, I recommend Excel 97-2003, or Excel 2010.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Learn Excel and VBA - Useful Links
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 09-12-2011, 12:57 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •