VBA & macros
Automate repeat work with macros and VBA code.
- Excel Macro Will Not Run? Fix the Common CausesIf an Excel macro will not run, first check that the workbook is saved as a macro-enabled file, that Excel has not…
- Excel Macro Subscript Out of Range: Causes and FixesExcel’s “Subscript out of range” message is VBA runtime error 9: a macro has asked for an item that does not exist…
- Excel VBA Keyboard Shortcut: Open, Run, and AssignIn Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor (VBE), where you can view and edit…
- Excel Error 9: Fix Subscript Out of Range in VBA SafelyExcel Error 9, “Subscript out of range,” is a VBA runtime error: a macro has tried to retrieve an item using an…
- Excel VBA Macro: How to Create, Run, and Save One SafelyTo create a VBA macro in Excel for Microsoft 365 on Windows, turn on the Developer tab, choose Developer > Visual Basic,…
- Documents Folder in Excel VBA: Open It SafelyTo open the current Windows user’s Documents folder from Excel VBA, get its location with the Windows Script Host’s SpecialFolders("MyDocuments") property, then…
- Count Cells by Color in Excel VBA: A Practical GuideTo count cells by fill color in Excel VBA, run a macro that compares each cell’s fill with a sample cell’s fill.…
- Count Cells by Color in Excel Without VBA: Best MethodsYes. You can count cells by color in Excel without writing VBA: filter the range by color and count the visible records,…
- Excel VBA Compile Error: Syntax Error Causes and FixesAn Excel VBA “Compile error: Syntax error” message means VBA cannot parse part of your code as valid language. In Excel for…
- Excel VBA Compile Error: Next Without For ExplainedIn Excel VBA, “Next without For” means VBA found a Next statement that it could not match to an open For or…
- Cannot Run Macro Error in Excel: Causes and SolutionsIf Excel says it cannot run a macro, first confirm that the macro exists in an open, macro-enabled workbook and that Excel…
- Array Errors in Excel VBA: Causes and FixesAn “array error” in Excel VBA is not one specific error: it usually means code has requested an array element outside the…
- Access VBA: Open an Excel File and Work With Its DataYes. Access VBA can open an Excel workbook by controlling the Excel application, or it can import worksheet data directly into an…
- Excel Macro to Import CSV Files AutomaticallyTo import a CSV file with an Excel macro, use VBA to ask you to select a file and load its contents…
- Excel Macro to Protect a Sheet: VBA Code and SetupTo protect an Excel worksheet with a macro, call the sheet’s VBA Protect method, for example Worksheets("Entry").Protect Password:="change-me". In Microsoft Excel for…
- Excel Macro Protect Sheet Options: VBA, Limits, and TipsIn Excel for Microsoft 365 on Windows, a VBA macro protects a worksheet with the Worksheet.Protect method: choose a password and specify…
- Excel Macro Text to Columns: VBA Setup and ExamplesTo run Excel’s Text to Columns tool with a macro, select the text column, then use VBA’s Range.TextToColumns method. The example below…
- Excel Macro Goal Seek: Automate a Target-Value SearchAn Excel Goal Seek macro uses VBA’s Range.GoalSeek method to make a formula cell reach a target by changing one input cell.…
- Excel Macro to Merge Cells: VBA Steps and LimitsYes. In Excel for Microsoft 365 on Windows, a VBA macro can merge the currently selected cells with the Range.Merge method. The…
- Excel Macro Named Range: How to Create and Use OneAn Excel macro named range is a descriptive name, such as SalesAmounts, that VBA can assign to a cell or range and…
- Excel Macro to Convert Text to Columns: VBA Guide and TipsYes. In Excel for Microsoft 365 on Windows, a VBA macro can convert text in a selected column into separate columns by…
- Excel VBA Button: Add One to a Worksheet Step by StepTo insert a VBA button in an Excel worksheet, show the Developer tab, choose Developer > Insert > Button under Form Controls,…
- Excel VBA Functions: Create and Use a Custom FunctionTo create a VBA function in Excel for Microsoft 365 on Windows, press Alt+F11, choose Insert > Module in the Visual Basic…
- Excel Goal Seek VBA Code for a Whole ColumnTo run Goal Seek down a column, loop through the populated rows and call Range.GoalSeek once per row: each call needs one…
- Excel Dashboard VBA: Build and Refresh a Useful DashboardExcel dashboard VBA is Visual Basic for Applications code that automates tasks such as refreshing data, updating PivotTables, and navigating between dashboard…
- Excel Code to Insert a Row: VBA and ShortcutsTo insert a worksheet row with Excel VBA, use Rows(ActiveCell.Row).Insert Shift:=xlDown in a macro; it inserts a row above the active cell.…
- Arrays in Excel VBA: How They Work and When to Use ThemAn array in Excel VBA is a variable that holds a group of related values under one name, with each value reached…
- Create a UserForm in Excel VBA: A Step-by-Step GuideTo create a UserForm in Excel VBA, open the Visual Basic Editor, choose Insert > UserForm, add controls from the Toolbox, and…
- Clear Function in Excel VBA: Add a Button to Clear CellsTo clear cells with a button in Excel VBA, use the ClearContents method in a macro, then assign that macro to a…
- Can Excel VBA Read Data From a PivotTable?Yes. Excel VBA can read a PivotTable’s values and labels through the PivotTable object model, using methods such as GetPivotData or ranges…