You are on page 1of 3

Macro Errors

excel
#1 Excel tutorial on the net
Excel
Introduction
Basics
Functions
Data Analysis
VBA
300 Examples
Ask us
Ad by save on. More Info | Hide These Ads
29k Like Like

This chapter teaches you how to deal with macro errors in Excel. First, let's create some errors.
Place a command button on your worksheet and add the following code lines:
x = 2
Range("A1").Valu = x
1. Click the command button on the sheet.
Result:
2. Click OK.
The variable x is not defined. Because we are using the Option Explicit statement at the start of our code, we have to declare all our variables. Excel
VBA has colored the x blue to indicate the error.
3. In the Visual Basic Editor, click Reset to stop the debugger.
Ads by OnlineBrowserAdvertising Ad Options
Excel Macro Errors - Excel VBA Easy http://www.excel-easy.com/vba/macro-errors.html
1 of 3 6/20/2014 11:01 AM
4. Correct the error by adding the following code line at the start of the code.
Dim x As Integer
You may have heard of the technique called debugging before. With this technique you can step through your code.
5. In the Visual Basic Editor, place your cursor before Private and press F8.
The first line turns yellow.
6. Press F8 three more times.
The following error appears.
Excel Macro Errors - Excel VBA Easy http://www.excel-easy.com/vba/macro-errors.html
2 of 3 6/20/2014 11:01 AM
The Range object has a property called Value. Value isn't spelled correctly here. Debugging is a great way to not only find errors, but also understand
code better. Our Debugging example program shows you how to single step through your code and see the effect of each code line on your worksheet.
Did you find this information helpful? Show your appreciation, vote for us.
29k Like Like
Go to Top: Macro Errors | Go to Next Chapter: String Manipulation
Learn more about macro errors, Go to the right >>

Learn more, it's easy
Debugging
Error Handling
Err Object
Interrupt a Macro
Macro Comments
Download Excel File
macro-errors.xls

Copyright (c) 2010-2014 www.excel-easy.com. Excel Macro Errors. All rights reserved.
excel 2010 tutorial | how to excel | microsoft excel 2010 | excel macro
Ads by OnlineBrowserAdvertising Ad Options
Excel Macro Errors - Excel VBA Easy http://www.excel-easy.com/vba/macro-errors.html
3 of 3 6/20/2014 11:01 AM

You might also like