• Breaking News

    Best Information About Technology

    Tuesday 14 March 2017

    MacroS — Automation

    Sometimes you repeat the same actions over and over again in a spreadsheet. You may, for example, have an established procedure for formatting cells. In many cases you can use the automatic formatting of tables, but often you will just highlight some cells using the gridlines and a frame. This means that
    you must select the cells, add gridlines, insert a frame and maybe a background colour.
    After some time, when you have formatted many tables in this way, you may want to look for a way to save sometime.
    Then "macros" is the answer. A macro is a "tape recording of a series of actions that you are doing and that you later can play again. A macro can record virtually everything you do. If you should later feel confident enough to start learning Visual Basic programming language, you will even be able to customise the macros, or turn them into small programs that can do a lot of things. We will not get that
    far in this book, but we will attempt to record and play a macro.

    1.1 Recording a Macro


    • Start by creating a spreadsheet like the one in Figure 01.
    The starting point for our exercise with macros.

    • Highlight the entire table i.e. cell range B2: E5.
    • In the Ribbon, select the View Tab and click on the Macros button located to the far right in the Ribbon.
    • Click on the menu item Record Macro.
    The macros Button.

    Now opens the window "Record Macro, where you have various choices. You can write a descriptive name for the macro, and you can assign a hotkey, so you have quick access to the macro.
    You must also decide where to save the macro. If you choose This Workbook it will be available only as long as you are working in the current Workbook. If you instead choose Personal Macro Workbook, the macro will always be available. The "Personal Macro Workbook" is a hidden workbook that is always open when you are Working in Excel. Therefore, all macros stored in it will always be available.
    • Give the macro the name "Format Table". You cannot use spaces in Macro names, so a " " sign is used instead.
    • Write a "t" as a shortcut. This enables you to activate the macro by holding down the CTRL key on your keyboard and press the T key.
    • Choose to save the macro in Personal Macro Workbook.
    Pre-record setting.

    • You can write a short descriptive text about the macro if you want. 
    • Click OK.

    Everything you do after this will be recorded in the macro. It is therefore a good idea to plan what the macro should do BEFORE you start recording.
    In this case, I have planned everything in advance. For example, I have already made a cell inside the table the active cell. Otherwise I would have to do it now by selecting, for example, cell E5, which would be recorded in the macro. That would not be a good idea, since the macro then always would start by making cell E5 the active cell. It would make the macro less useful as cell E5 is not always a part of my tables.
    • Right-click inside the table and choose Format Cells from the menu that appears. 
    • In the window that opens, click on the Border Tab. 
    • Choose the thickestline style and choose a blue colour. 
    • Then click on Contour. 
    • Choose one of the thin line styles and choose agreen colour. 
    • Then click on Interior.
    • Click OK.

    Now you have formatted the table and the recording must be stopped. At the bottom left of the screen (next to the text "Clear") there is a small square. It is a "stop button" which stops the macro recording.
    • Click on the Stop button
    The Stop Button.
    Now the macro is has completed recording. There is nothing further to do before we play it.

    1.2 Playa Macro

    • Select a random cell region. You decide where and how large the region should be.
    • Hold the CTRL key down on the keyboard and press the T key.

    Now the macro is being played, and the cell region you selected gets green grid lines with a blue border around it.
    You can record as many macros as you like. You can view a list of them by clicking the View Tab in the Ribbon, and then click the Macros button. In the menu that appears, click View Macros.
    List of your macros.
    In the macro window, you can play and delete macros. If you know how to program in Visual Basic, you can also edit your macros. Finally, you can also change the settings to for example assign a different shortcut.

    9.3 AButton for Your Macro

    Keyboard shortcuts are good, but you can also add a button into the toolbar, "Quick Access, which activates the macro.
    Quick Access.
    • Right-click anywhere on the toolbar "Quick Access. It could for example be the disk icon.
    • Click on customize Quick Access Toolbar.
    • In the window that opens, choose the item Customize in the right side.
    • Under "Choose commands from click Macros.
    Choose commandos from "Macros".

    • In the list, you can now select your macro, called “PERSONAL.XLSB! Format Tabel”. Click it, then click on the Addi>> button.
    • Click OK.

    Now you have an extra button in the Toolbar "Quick Access. You can go ahead and try it.
    A button for your macro.

    No comments:

    Post a Comment

    143