Article ID: 213630 - View products that this article applies to.
This article was previously published under Q213630
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 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 using Select Case statements, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Using Select Case Statements in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
For more information about the IF statement, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Using If...Then...Else Statements in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
For 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:
226118For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
(https://support.microsoft.com/kb/226118/EN-US/ )Programming resources for Visual Basic for Applications
(https://support.microsoft.com/kb/212536/EN-US/ )How to run sample code from Knowledge Base articles
Article ID: 213630 - Last Review: September 18, 2011 - Revision: 7.0