A List of Excel VBA Commands [Free PDF Download]

Excel is a powerful tool that is used by millions of people worldwide to analyze, organize and present data. While Excel offers many built-in functions and features, sometimes users need more flexibility and customization to meet their specific needs. This is where Visual Basic for Applications (VBA) comes in. VBA is a programming language that is integrated into Excel and allows users to automate tasks, customize the application, and create custom solutions. In this article, I will provide a comprehensive list of VBA commands that are available in Excel.

Download Excel VBA Commands List

What are VBA Commands in Excel?

Excel VBA commands are the building blocks of VBA programming in Excel. These commands allow you to automate repetitive tasks, customize the Excel interface, and create custom solutions that are tailored to your specific needs. Here are some examples of Excel VBA commands:

A. Range and Cell Commands

  • Range(“A1”).Value = “Hello World” – assigns the value “Hello World” to cell A1.
  • Range(“A1:B5”).ClearContents – clears the contents of cells A1 to B5.
  • Offset(1, 0).Select – selects the cell one row below the current active cell.

B. Worksheet and Workbook Commands

  • Worksheets(“Sheet1”).Activate – activates the worksheet named “Sheet1”.
  • Open(“C:\My Documents\Book1.xlsx”) – opens the workbook located at the specified file path.
  • SaveAs(“C:\My Documents\New Book.xlsx”) – saves the active workbook with a new file name and location.

C. PivotTable and PivotChart Commands

  • PivotTables(“PivotTable1”).RefreshTable – refreshes the data in PivotTable1.
  • PivotCharts(“PivotChart1”).ChartType = xlLine – changes the chart type of PivotChart1 to a line chart.
  • PivotFields(“Category”).Orientation = xlRowField – adds the Category field to the row area of the Pivot Table.

D. Chart Commands

  • SeriesCollection(1).XValues = “=Sheet1!$A$1:$A$10” – sets the X-axis values of the first series in the active chart to cells A1 to A10 in Sheet1.
  • ChartTitle.Text = “Sales by Region” – sets the chart title to “Sales by Region”.
  • ChartType = xlColumnClustered – changes the chart type to a clustered column chart.

These are just a few examples of the many Excel VBA commands that are available. By mastering these commands, you can create powerful macros and solutions that automate tasks, analyze data, and customize the Excel interface.

List of Commonly VBA Commands in Excel

1. Range and Cell Selection

CommandDescription
Range()Selects a range of cells in a worksheet.
Cells()Returns a specific cell or a range of cells.
ActiveCellReturns the active cell, which is the currently selected cell in a worksheet.
Offset()Returns a range of cells that is offset from a given range.

2. Clipboard

CommandDescription
Copy()Copies the selected range to the Clipboard.
Paste()Pastes the contents of the Clipboard into the selected range.

3. Worksheets and Sheets

CommandDescription
Worksheets()Returns a collection of all the worksheets in a workbook.
ActiveSheetReturns the active worksheet, which is the currently displayed worksheet in a workbook.
Sheets()Returns a collection of all the sheets in a workbook, including chart sheets and other sheet types.
ProtectProtects a worksheet or workbook structure with a password.
UnprotectRemoves password protection from a worksheet or workbook structure.

4. Workbooks

CommandDescription
Workbooks()Returns a collection of all the open workbooks.
ActiveWorkbookReturns the active workbook, which is the currently displayed workbook.
SaveAs()Saves a workbook with a different file name or format.
Open()Opens a workbook from a file path.
SaveSaves changes to a workbook or a copy of a workbook with a new name or location.
CloseCloses a workbook.
ThisWorkbookReturns a reference to the workbook that contains the VBA code that is currently running.

5. PivotTables

CommandDescription
PivotTables()Returns a collection of all the Pivot Tables in a worksheet.
PivotCharts()Returns a collection of all the Pivot Charts in a worksheet.
PivotFields()Returns a collection of all the Pivot Fields in a Pivot Table.
RefreshTable()Refreshes the data in a Pivot Table.
PivotSelect()Selects a range in a Pivot Table.
PivotLayout()Sets the layout of a Pivot Table.
PivotTableWizard()Displays the Pivot Table and Pivot Chart Wizard dialog box.

6. Charts

CommandDescription
ActiveChartReturns the active chart, which is the currently selected chart in a worksheet.
ChartObjects()Returns a collection of all the chart objects in a worksheet.
SeriesCollection()Returns a collection of all the series in a chart.
ChartTitleRepresents the title of a chart.
ChartTypeSets or returns the chart type for a chart.
SetElementSets the appearance of a chart element, such as the chart title or axis labels.

7. Data Validation

CommandDescription
DataValidationAdds data validation to a range of cells in a worksheet.
ValidationTypeSets or returns the type of data validation to apply to a range of cells.
InputTitleSets or returns the title of the input message that appears when a user selects a cell with data validation.
InputMessageSets or returns the text of the input message that appears when a user selects a cell with data validation.
ErrorTitleSets or returns the title of the error message that appears when a user enters invalid data in a cell with data validation.
ErrorMessageSets or returns the text of the error message that appears when a user enters invalid data in a cell with data validation.
ShowInputDetermines whether to display the input message when a user selects a cell with data validation.
ShowErrorDetermines whether to display the error message when a user enters invalid data in a cell with data validation.
InCellDropdownDetermines whether to display a dropdown arrow in cells with data validation that allow a list.
IgnoreBlankDetermines whether to allow blank cells when validating data.
Formula1Sets or returns the first value or expression to use in a data validation rule.
Formula2Sets or returns the second value or expression to use in a data validation rule, if applicable.
AddAdds a data validation rule to a range of cells.
ModifyModifies an existing data validation rule for a range of cells.
DeleteDeletes the data validation rule for a range of cells.

8. Miscellaneous

CommandDescription
MsgBoxDisplays a message box with a message and optional buttons and icons.
InputBoxDisplays an input box to get input from the user.
CreateObjectCreates a reference to an external object or application, such as a Word document or an Outlook email message.
ShellRuns an external program or command.
TimerReturns the number of seconds since midnight.
EnvironReturns the value of an environment variable, such as the user’s username or the path to the Windows directory.
ClearContents()Clears the contents of the selected range.

Conclusion

Excel VBA commands offer a powerful toolset for users who need to automate tasks, customize the application, and create custom solutions. While mastering VBA can take time and practice, the benefits are well worth the effort. Whether you’re an Excel power user or a beginner, learning VBA commands can help you take your skills to the next level and unlock new levels of productivity and creativity.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *