Article ID: 141691 - View products that this article applies to.
This article was previously published under Q141691
In Microsoft Visual Basic for Applications, there are two statements that you can use to perform a conditional test: an If...Then...Else statement or a Select Case statement. The If...Then...Else statement executes a group of statements based on the value of an expression, and the Select Case statement executes one of several of statements based on the value of an expression.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following sample macros show how to use the If...Then...Else and the Select Case statements.
Sample Macro Using If...Then...Else Statement
Sample Macro Using Select Case Statement
For more information about controlling program flow, click Answer Wizard on the Help menu and type:
tell me about conditional programming"Visual Basic User's Guide," version 5.0, Chapter 7, "Controlling How Your Code Runs"
Microsoft Press: "Microsoft Excel/Visual Basic Programmer's Guide", version 7.0, Chapter 3, "Controlling Program Flow"
In Microsoft Excel version 5.0, click Contents on the Help menu, click Programming With Visual Basic; then click the Search button and type:
ifFor additional information about getting help with Visual Basic for Applications, please click the article number below to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/163435/EN-US/ )VBA: Programming Resources for Visual Basic for Applications
Article ID: 141691 - Last Review: October 11, 2006 - Revision: 2.3
Contact us for more help
Connect with Answer Desk for expert help.