VBA Cheat Sheets Reference this page for lists of all common VBA Commands & Syntax. You will find many basic commands (ex. Insert a sheet) and some advanced syntax (ex. Working with arrays). Sep 10, 2019 - VBA Cheat Sheet. VBA syntax, variables, loops, conditions, Classes, Types, Enumerations etc. The best VBA cheat sheet out there! This VBA Cheat Sheet is in pdf and Microsoft Word format for your convenience. We created the reference guide after having used VBA for thousands of hours in personal and professional settings. It provides concrete examples where necessary, using VBA that.
Download this 2-page SQL Basics Cheat Sheet in PDF or PNG format, print it out, and stick to your desk.
The SQL Basics Cheat Sheet provides you with the syntax of all basics clauses, shows you how to write different conditions, and has examples. You can download this cheat sheet as follows:
You may also read the contents here:
SQL Basics Cheat Sheet
SQL
SQL, or Structured Query Language, is a language to talk to databases. It allows you to select specific data and to build complex reports. Today, SQL is a universal language of data. It is used in practically all technologies that process data.
SAMPLE DATA
QUERYING SINGLE TABLE
Fetch all columns from the country
table:
Fetch id and name columns from the city table:
Fetch city names sorted by the rating
column in the default ASCending order:
Fetch city names sorted by the rating
column in the DESCending order:
Aliases
Columns
Tables
FILTERING THE OUTPUT
COMPARISON OPERATORS
Fetch names of cities that have a rating above 3:Fetch names of cities that are neither Berlin nor Madrid:TEXT OPERATORS
Fetch names of cities that start with a 'P' or end with an 's':Fetch names of cities that start with any letter followed by'ublin' (like Dublin in Ireland or Lublin in Poland):OTHER OPERATORS
Fetch names of cities that have a population between 500K and 5M:Fetch names of cities that don't miss a rating value:Fetch names of cities that are in countries with IDs 1, 4, 7, or 8:QUERYING MULTIPLE TABLES
INNER JOIN
JOIN
(or explicitly INNER JOIN
) returns rows that have matching values in both tables.
LEFT JOIN
LEFT JOIN
returns all rows from the left table with corresponding rows from the right table. If there's no matching row, NULL
s are returned as values from the second table.
RIGHT JOIN
RIGHT JOIN
returns all rows from the right table with corresponding rows from the left table. If there's no matching row, NULL
s are returned as values from the left table.
FULL JOIN
FULL JOIN
(or explicitly FULL OUTER JOIN
) returns all rows from both tables – if there's no matching row in the second table, NULL
s are returned.
CROSS JOIN
CROSS JOIN
returns all possible combinations of rows from both tables. There are two syntaxes available.
NATURAL JOIN
NATURAL JOIN
will join tables by all columns with the same name.
NATURAL JOIN
used these columns to match rows:city.id
, city.name
, country.id
, country.name
.NATURAL JOIN
is very rarely used in practice.
AGGREGATION AND GROUPING
GROUP BY
groups together rows that have the same values in specified columns. It computes summaries (aggregates) for each unique combination of values.
AGGREGATE FUNCTIONS
avg(expr)
− average value for rows within the groupcount(expr)
− count of values for rows within the groupmax(expr)
− maximum value within the groupmin(expr)
− minimum value within the groupsum(expr)
− sum of values within the group
EXAMPLE QUERIES
Find out the number of cities:
Find out the number of cities with non-null ratings:
Find out the number of distinctive country values:
Find out the smallest and the greatest country populations:
Find out the total population of cities in respective countries:
Find out the average rating for cities in respective countries if the average is above 3.0:
SUBQUERIES
A subquery is a query that is nested inside another query, or inside another subquery. There are different types of subqueries.
Access Vba Syntax Cheat Sheet
SINGLE VALUE
The simplest subquery returns exactly one column and exactly one row. It can be used with comparison operators =
, <
, <=
, >
, or >=
.
This query finds cities with the same rating as Paris:
MULTIPLE VALUES
A subquery can also return multiple columns or multiple rows. Such subqueries can be used with operators IN
, EXISTS
, ALL
, or ANY
.
This query finds cities in countries that have a population above 20M:
CORRELATED
A correlated subquery refers to the tables introduced in the outer query. A correlated subquery depends on the outer query. It cannot be run independently from the outer query.
This query finds cities with a population greater than the average population in the country:
This query finds countries that have at least one city:SET OPERATIONS
Set operations are used to combine the results of two or more queries into a single result. The combined queries must return the same number of columns and compatible data types. The names of the corresponding columns can be different
UNION
UNION
combines the results of two result sets and removes duplicates. UNION ALL
doesn't remove duplicate rows.
This query displays German cyclists together with German skaters:
INTERSECT
INTERSECT
returns only rows that appear in both result sets.
Excel Vba Cheat Sheet
This query displays German cyclists who are also German skaters at the same time:
EXCEPT
EXCEPT
returns only the rows that appear in the first result set but do not appear in the second result set.
This query displays German cyclists unless they are also German skaters at the same time:
You may also like
The syntax in a Visual Basic Help topic for a method, function, or statement shows all the elements necessary to use the method, function, or statement correctly. The examples in this topic explain how to interpret the most common syntax elements.
Activate method syntax
object.Activate
In the Activate method syntax, the italic word 'object' is a placeholder for information you supply—in this case, code that returns an object. Words that are bold should be typed exactly as they appear. For example, the following procedure activates the second window in the active document.
MsgBox function syntax
MsgBox (prompt, [ buttons, ] [ title, ] [ helpfile, context ])
In the MsgBox function syntax, the italic words are named arguments of the function. Arguments enclosed in brackets are optional. (Do not type the brackets in your Visual Basic code.) For the MsgBox function, the only argument you must provide is the text for the prompt.
Arguments for functions and methods can be specified in code either by position or by name. To specify arguments by position, follow the order presented in the syntax, separating each argument with a comma, for example:
To specify an argument by name, use the argument name followed by a colon and an equal sign (:=), and the argument's value. You can specify named arguments in any order, for example:
The syntax for functions and some methods shows the arguments enclosed in parentheses. These functions and methods return values, so you must enclose the arguments in parentheses to assign the value to a variable. If you ignore the return value or if you don't pass arguments at all, don't include the parentheses. Methods that don't return values do not need their arguments enclosed in parentheses. These guidelines apply whether you are using positional arguments or named arguments.
In the following example, the return value from the MsgBox function is a number indicating the selected button that is stored in the variable myVar
. Because the return value is used, parentheses are required. Another message box then displays the value of the variable.
Option Compare statement syntax
Option Compare { Binary | Text | Database }
In the Option Compare statement syntax, the braces and vertical bar indicate a mandatory choice between three items. (Do not type the braces in the Visual Basic statement). For example, the following statement specifies that within the module, strings will be compared in a sort order that is not case-sensitive.
Dim statement syntax
Dimvarname [([ subscripts ])] [ Astype, ] [ varname [([ subscripts ])] [ Astype ]] . . .
In the Dim statement syntax, the word Dim is a required keyword. The only required element is varname (the variable name).
For example, the following statement creates three variables: myVar
, nextVar
, and thirdVar
. These are automatically declared as Variant variables.
The following example declares a variable as a String. Including a data type saves memory and can help you find errors in your code.
To declare several variables in one statement, include the data type for each variable. Variables declared without a data type are automatically declared as Variant.
In the following statement, x
and y
are assigned the Variant data type. Only z
is assigned the Integer data type.
The shorthand to declare x
and y
as Integer in the statement above is:
The shorthand for the types is: % -integer; & -long; @ -currency; # -double; ! -single; $ -string
If you are declaring an array variable, you must include parentheses. The subscripts are optional. The following statement dimensions a dynamic array, myArray
.
Excel Vba Syntax Cheat Sheet
See also
Support and feedback
Oracle Sql Syntax Cheat Sheet
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.