Download Complete EXCEL VBA Programming By Examples Programming For Complete Beginners Step By Step Illustrated Guide to Mastering Excel VBA Thanh Tran PDF for All Chapters
Download Complete EXCEL VBA Programming By Examples Programming For Complete Beginners Step By Step Illustrated Guide to Mastering Excel VBA Thanh Tran PDF for All Chapters
com
https://textbookfull.com/product/excel-vba-programming-by-
examples-programming-for-complete-beginners-step-by-step-
illustrated-guide-to-mastering-excel-vba-thanh-tran/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/excel-vba-programming-for-
dummies-5th-edition-michael-alexander/
textboxfull.com
https://textbookfull.com/product/programming-excel-with-vba-a-
practical-real-world-guide-flavio-morgado/
textboxfull.com
https://textbookfull.com/product/essential-excel-2019-a-step-by-step-
guide-david-slager/
textboxfull.com
Excel 2019 Pivot Tables & Introduction To Dashboards The
Step-By-Step Guide 3rd Edition Benton
https://textbookfull.com/product/excel-2019-pivot-tables-introduction-
to-dashboards-the-step-by-step-guide-3rd-edition-benton/
textboxfull.com
https://textbookfull.com/product/python-programming-a-step-by-step-
guide-from-beginner-to-advance-second-edition-eddison/
textboxfull.com
https://textbookfull.com/product/learn-to-program-with-
python-3-a-step-by-step-guide-to-programming-irv-kalb/
textboxfull.com
EXCEL VBA Programming By
Examples
P rogramming F or C omplete B eginners , S tep -B y -S tep
I llustrated G uide to M astering E xcel VBA
thanh tran
Copyright © 2019 by Thanh Tran
Table of Contents
Place a command button on your worksheet and add the following code lines:
1. First, we declare a variable called temp of type Double.
Dim temp As Double
2. We initialize the variable temp with the value of cell A1.
temp = Range("A1").Value
3. Now we can safely write the value of cell B1 to cell A1 (we have stored the
value of cell A1 to temp so we will not lose it).
Range("A1").Value = Range("B1").Value
4. Finally, we write the value of cell A1 (written to temp) to cell B1.
Range("B1").Value = temp
5. Click the command button two times.
Result:
Run Code from a Module
As a beginner to Excel VBA, you might find it difficult to decide
where to put your VBA code. The Create a Macrochapter illustrates
how to run code by clicking on a command button. This example
teaches you how to run code from a module.
1. Open the Visual Basic Editor.
2. Click Insert, Module.
End Sub
Note: a procedure is either a sub or a function. Learn more
about functions and subs here, if you like.
4. The sub changes the background color of your worksheet to cyan.
To achieve this, add the following code line.
Cells.Interior.ColorIndex = 28
Note: instead of ColorIndex number 28 (cyan), you can use any
ColorIndex number.
To run the procedure, execute the following steps.
5. Click Macros.
Result:
Note: code placed into a module is available to the whole workbook.
That means, you can select Sheet2 or Sheet3 and change the
background color of these sheets as well. The Add a Macro to the
Toolbar program illustrates how to make a macro available to all
your workbooks (Excel files). Remember, code placed on a sheet
(assigned to a command button) is only available for that particular
sheet.
Macro Recorder
he Macro Recorder, a very useful tool included in Excel VBA,
records every task you perform with Excel. All you have to do is
record a specific task once. Next, you can execute the task over and
over with the click of a button. The Macro Recorder is also a great
help when you don't know how to program a specific task in Excel
VBA. Simply open the Visual Basic Editor after recording the task to
see how it can be programmed.
Unfortunately, there are a lot of things you cannot do with the Macro
Recorder. For example, you cannot loop through a range of data with
the Macro Recorder. Moreover, the Macro Recorder uses a lot more
code than is required, which can slow your process down.
Record a Macro
1. On the Developer tab, click Record Macro.
2. Enter a name.
3. Select This Workbook from the drop-down list. As a result, the
macro will only be available in the current workbook.
Note: if you store your macro in Personal Macro Workbook, the
macro will be available to all your workbooks (Excel files). This is
possible because Excel stores your macro in a hidden workbook that
opens automatically when Excel starts. If you store your macro in
New Workbook, the macro will only be available in an automatically
new opened workbook.
4. Click OK.
5. Right mouse click on the active cell (selected cell). Be sure not to
select any other cell! Next, click Format Cells.
6. Select Percentage.
7. Click OK.
8. Finally, click Stop Recording.
Result:
See the Macro
To take a look at the macro, open the Visual Basic Editor.
Note: the macro has been placed into a module called Module1.
Code placed into a module is available to the whole workbook. That
means, you can select Sheet2 or Sheet3 and change the number
format of cells on these sheets as well. Remember, code placed on a
sheet (assigned to a command button) is only available for that
particular sheet.
Use Relative References
By default, Excel records macros in absolute mode. However,
sometimes it is useful to record macros in relative mode. This
program teaches you how to do this. If you don't know how
to record a macro, we highly recommend you to read this example
first.
Explanation: you can see that this is the exact same code line used
at step 3.
Add a Macro to the Toolbar
If you use an Excel macro frequently, you can add it to the Quick
Access Toolbar. This way you can quickly access your macro. First,
we record an empty macro.
1. On the Developer tab, click Record Macro.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com