tech on the net
Home About Us Feedback Site Map

Microsoft

Access Excel Word

Database

SQL Oracle / PLSQL SQL Server MySQL MariaDB PostgreSQL

Web Development

HTML CSS Color Picker

Language

C Language

More

ASCII Table Linux UNIX Java Clipart Joke of the Moment
Share this page:

MS Excel: AND Function (VBA)

Learn how to use the Excel AND function (in VBA) with syntax and examples.

Description

The Microsoft Excel AND function returns TRUE if all conditions are TRUE. It returns FALSE if any of the conditions are FALSE. Please note that the WS version of the AND function has different syntax.

Syntax

The syntax for the Microsoft Excel AND function is:

condition1 And condition2 [... And condition_n]

Parameters or Arguments

condition1, condition2, ... condition_n are expressions that you want to test that can either be TRUE or FALSE.

Applies To

The AND function can be used in the following versions of Microsoft Excel:

  • Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Excel Function

The AND function can be used in Microsoft Excel as the following type of function:

  • VBA function (VBA)

Example (as VBA Function)

Let's look at some Excel AND function examples and explore how to use the AND function in Excel VBA code.

This first example combines the AND function with the IF Statement in VBA code:

If LWebsite = "TechOnTheNet.com" And LPages <= 10 Then
   LBandwidth = "Low"
Else
   LBandwidth = "High"
End If

This would set the LBandwidth variable to the string value "Low" if both LWebsite was "TechOnTheNet.com" and LPages <= 10. Otherwise, it would set the LBandwidth variable to the string value "High".

This second example uses the AND function with the OR function in VBA, for example:

If (LWebsite = "TechOnTheNet.com" Or LWebsite = "CheckYourMath.com") And LPages <= 10 Then
   LBandwidth = "Low"
Else
   LBandwidth = "High"
End If

This would set the LBandwidth variable to the string value "Low" if LWebsite was either "TechOnTheNet.com" or "CheckYourMath.com" and LPages <= 10. Otherwise, it would set the LBandwidth variable to the string value "High".