VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA Clear Cell Fill Color: Methods and ExamplesTo clear a cell’s fill color with VBA, set its Interior.Pattern to xlPatternNone, such as Range("A1").Interior.Pattern = xlPatternNone. For a range, use…
- Excel VBA: Check Whether a Sheet Is ProtectedIn Excel VBA, check Worksheet.ProtectContents to see whether a worksheet’s cells are protected. For a broader check that also detects protection of…
- Excel VBA Clipboard Error: Causes and FixesAn Excel VBA clipboard error usually means Excel cannot complete a copy or paste because the clipboard is busy, the copied content…
- Excel VBA Change Cell Font Color: Code and ExamplesTo change a cell’s font color with Excel VBA, set the range’s Font.Color property, usually with the RGB function: Range("A1").Font.Color = RGB(255,…
- Excel VBA: How to Change Cell Formats to GeneralTo change a cell’s number format to General with VBA, assign General to its NumberFormat property: Worksheets("Sheet1").Range("A1").NumberFormat = "General". This changes how…
- Excel VBA: Change Cell and Range FormatsTo change a cell’s format with Excel VBA, assign a property such as NumberFormat, Font.Bold, or Interior.Color to a Range. For example,…
- Excel VBA: How to Change a Cell’s ColorTo change a cell’s color with Excel VBA, set its Interior.Color property, such as Range("B2").Interior.Color = RGB(255, 230, 153) for a pale…
- Excel VBA Cell Interior Color: Read, Set, and ClearIn Excel VBA, a cell’s fill color is controlled through its Interior object: set it with Range("A1").Interior.Color = RGB(255, 230, 153), read…
- Excel VBA: Center an Image in a Cell Without DistortionTo center an image in an Excel cell with VBA, select the picture, run a macro that scales it to fit the…
- Excel VBA Cell Fill Color: Read, Set, and TroubleshootIn Excel VBA, set a cell’s fill color with its Interior.Color property, usually using RGB(red, green, blue); for example, Range("A1").Interior.Color = RGB(255,…
- Excel VBA Cell Interior Color: RGB, Hex, and Code ExamplesIn Excel VBA, a cell’s fill color is read or set with Range("A1").Interior.Color, which uses a numeric color value rather than a…
- Excel VBA Cell Text Color: Set, Read, and ResetIn Excel VBA, set a cell’s text color with its Font.Color property, usually assigning an RGB value: Range("B2").Font.Color = RGB(192, 0, 0).…
- Excel VBA Cell Color RGB: Set and Read ColorsIn Excel VBA, set a cell’s fill color with Range("A1").Interior.Color = RGB(255, 0, 0); that example makes the cell red. Use .Font.Color…
- Excel VBA Cell Background Color: Fill Cells in CodeTo change a cell’s background color with Excel VBA, set its Interior.Color property—for example, Range("A1").Interior.Color = RGB(255, 255, 0) fills A1 yellow.…
- Excel VBA Cell Color: Read, Set, and Fix Common IssuesIn Excel VBA, set a cell’s fill color with Range("A1").Interior.Color = RGB(255, 230, 153), and read it with Range("A1").Interior.Color. Use Interior.Color for…
- Excel VBA Automation Error: Causes, Fixes, and Checks“Excel VBA Automation error: Exception occurred” is a broad error from an object that VBA is controlling, often another Office app or…
- Excel VBA: Stop on Error or Cancel a Running MacroTo stop an Excel VBA macro when an error occurs, let the error remain unhandled or use an error handler that reports…
- Excel VBA Select Case Examples: Syntax and Common UsesIn Excel VBA, Select Case chooses which block of code to run based on the value of an expression. Use it when…
- Excel VBA: How to Assign a Keyboard Shortcut to a MacroTo assign a keyboard shortcut in Excel for Microsoft 365 on Windows, press Alt+F8, select the macro, choose Options, enter a letter…
- Excel VBA Application-Defined Error: Causes and FixesAn Excel VBA “application-defined or object-defined error” is usually a runtime error 1004: Excel could not carry out an operation requested by…
- Excel VBA Application-Defined or Object-Defined ErrorIn Excel VBA, “Application-defined or object-defined error” is usually runtime error 1004: Excel could not complete an operation requested through its object…
- Excel VBA: Add a New Sheet at the End and Name It SafelyTo add a worksheet after the workbook’s last tab and name it in Excel VBA, use Worksheets.Add with the last item in…
- Excel VBA: Add a New Worksheet with a Specific NameTo add a worksheet and give it a name with Excel VBA, add the sheet, then set its Name property. This example…
- Excel VBA Advanced Filter: Using Multiple CriteriaTo use multiple criteria with Excel VBA Advanced Filter, put conditions that must all be true on the same criteria row, and…
- Excel VBA: Add a Keyboard Shortcut to a MacroYes. In Excel for Microsoft 365 on Windows, open Developer > Macros, select your macro, choose Options, and enter a letter to…
- Excel VBA: Add a New Sheet and Rename It AutomaticallyTo add a worksheet and give it a name with Excel VBA, use Worksheets.Add to create the sheet, then assign its Name…
- Excel VBA: Sum Cells by Fill ColorIf by “add cells” you mean total their numbers, a VBA macro can sum values in a range when each cell’s fill…
- Excel VBA: Add Cells With Fill ColorTo insert a cell and give it a fill color with VBA, use the cell’s Insert method, then set its Interior.Color property.…
- 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 Filter Table: VBA Code, Steps, and TipsTo filter an Excel table with a macro, use VBA’s AutoFilter method on the table and specify the column and criteria. For…