VBA & macros
Automate repeat work with macros and VBA code.
- Excel Macro to Insert an Image: VBA Steps and OptionsTo insert an image with an Excel macro, use VBA’s Shapes.AddPicture method. The example below opens a file picker, inserts the selected…
- Macro Meal Planner Template Excel: Setup and FormulasA macro meal planner template in Excel can track each meal’s calories, protein, carbohydrates, and fat, then total those figures by day.…
- Insert Row in Excel: Shortcut and VBA OptionsIn Excel for Microsoft 365 on Windows, select the row where the new row should go with Shift+Space, then press Ctrl+Shift++ (on…
- Excel VBA Expected Error: How to Find and Fix ItExcel VBA has no single error called “expected error”; the message usually means the compiler expected a particular word, symbol, or expression…
- Excel VBA Like Statement: Patterns and ExamplesIn Excel VBA, the Like operator compares a string with a pattern and returns whether the string matches it. Use wildcard characters…
- VBA Code to Open an Excel File: A Complete VBA GuideTo open an existing Excel workbook with VBA, use Workbooks.Open and provide the file’s full path. Paste the complete macro below into…
- VBA in Excel: Open the Editor with a Keyboard ShortcutTo open the VBA editor in Excel for Microsoft 365 on Windows, press Alt+F11. This opens the Visual Basic Editor (VBE), where…
- Excel Macro Shortcut: Open the Macro Dialog QuicklyIn Excel for Microsoft 365 on Windows, press Alt+F8 to open the Macro dialog, where you can find, run, or edit available…
- Open an Excel File Using VBA: Step-by-Step GuideTo open an Excel workbook with VBA, use the Workbooks.Open method and give it the file’s full path, for example Set wb…
- Open an Excel File for Reading in VBA: A Step-by-Step GuideTo open an Excel workbook for reading in VBA, use Workbooks.Open with ReadOnly:=True, then refer to the workbook and worksheet through variables.…
- Delete an Excel Macro: Safe Steps for Windows and MacTo delete an Excel macro in Microsoft 365 for Windows, open the workbook, choose Developer > Macros, select the macro, and click…
- Count Jess in Excel VBA: A Step-by-Step GuideTo count cells whose value is Jess, run a VBA macro that checks a chosen column and counts case-insensitive exact matches. The…
- Close an Excel Workbook with VBA Without Losing WorkTo close an Excel workbook with VBA, call its Close method and decide whether to save changes: choose True to save, False…
- Excel AutoFit Using View Code: Set It Up with VBATo AutoFit columns automatically when you edit a worksheet, right-click that sheet’s tab, choose View Code, and add a Worksheet_Change VBA event…
- Autofit in Excel Using VBA for Rows and ColumnsTo autofit Excel cells with code, run VBA that applies AutoFit to the used range: use ws.UsedRange.Columns.AutoFit for column widths and ws.UsedRange.Rows.AutoFit…
- Find Last Empty Row in Excel VBA: Reliable MethodsTo find the next empty row after the data in an Excel column, use End(xlUp) from the bottom of that column, then…
- Excel VBA Or in If Statements: Syntax and ExamplesIn Excel VBA, use the Or operator between complete conditions inside an If statement: If status = "Open" Or status = "Pending"…
- Excel VBA: Use Variables in a Range StatementYes. In Excel VBA, pass a variable to Range without putting the variable name in quotation marks, such as Set target =…
- Excel VBA VB Colors: Constants, RGB, and Cell FormattingIn Excel VBA, vbRed, vbBlue, and the other vb color constants are built-in names for eight basic colors. Assign them to a…
- Excel VBA Unique List: How to Create One ReliablyTo create a unique list with Excel VBA, read the source range, keep the first occurrence of each value, and write the…
- Excel VBA: Trigger a Macro When a Cell Value ChangesYes. In Excel for Microsoft 365 on Windows, put a Worksheet_Change event procedure in the worksheet’s code module to run VBA when…
- Excel VBA to Open Another Workbook: Code and TipsTo open another Excel file with VBA, call Workbooks.Open and supply the file’s full path. For example, Set targetWb = Workbooks.Open(Filename:="C:\Reports\Quarterly.xlsx") opens…
- Excel VBA Syntax Error: Causes, Examples, and FixesAn Excel VBA syntax error means the Visual Basic for Applications editor cannot parse part of your code as valid VBA. In…
- Excel VBA Text Color: Change Font and Cell Colors EasilyTo change text color in Excel VBA, set a range’s Font.Color property, usually with RGB(red, green, blue). For example, Range("A1").Font.Color = RGB(255,…
- Excel VBA: Substitute Text in Cells or StringsTo substitute text with VBA, use the built-in Replace function for a string, or the Range.Replace method to change matching text in…
- Excel VBA Macro Shortcut: How to Assign and Use ItIn Excel for Microsoft 365 on Windows, assign a shortcut to a VBA macro by choosing Developer > Code > Macros, selecting…
- Excel VBA: Sum Cells by Fill ColorTo sum numbers in cells with a particular fill color, add a VBA function to a standard module and call it with…
- Excel VBA: Set Cell Text Color with Font.ColorTo set a cell’s text color in Excel VBA, change the cell’s Font.Color property, usually with the RGB function: Range("A1").Font.Color = RGB(255,…
- Excel VBA: Set a Cell’s Background Color with RGB ValuesTo set a cell’s background color in Excel VBA, assign a color to its Interior.Color property—for example, Range("B2").Interior.Color = RGB(255, 255, 0)…
- Excel VBA Set Cell Color: ColorIndex, RGB, and MoreTo set a cell’s fill color with VBA, assign a color to its Interior.Color property—for example, use RGB(255, 0, 0) for red.…