VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA: How to Open the Editor and Run Macros SafelyIn Excel for Microsoft 365 on Windows, press Alt+F11 to open the VBA editor, or choose Developer > Visual Basic. To open…
- Excel VBA Copy: How to Copy Cells, Sheets, and FilesTo copy cells with Excel VBA, use Range.Copy with a destination, such as Worksheets("Sales").Range("A1:D20").Copy Destination:=Worksheets("Summary").Range("A1"). This copies the cells’ formulas or values…
- Excel VBA Data Types: Choosing the Right Variable for MacrosExcel VBA data types define what kind of value a variable can hold, such as a whole number, decimal, date, text, or…
- Excel VBA Delete Row: Methods, Examples, and Best PracticesTo delete a worksheet row with Excel VBA, reference the worksheet and call its Rows collection’s Delete method—for example, ws.Rows(5).Delete deletes row…
- How to List All Files in a Folder Using Excel VBATo list files directly inside a folder in Excel for Microsoft 365 on Windows, run a VBA macro that reads the folder’s…
- Print GMT Time Using Excel VBATo print the current GMT time with Excel VBA on Windows, call the Windows GetSystemTime API and send its result to the…
- Read a Text File with Excel VBA: Methods and ExamplesYes. In Excel for Microsoft 365 on Windows, VBA can read a plain-text file with the Open and Line Input # statements,…
- Insert a Table in Excel Using VBA: Code and TipsIn Excel for Microsoft 365 on Windows, create a table with VBA by specifying the range that contains the headers and data,…
- Insert Borders in Excel Using VBA: Code and TipsTo insert borders with VBA, set the LineStyle, Weight, and optionally Color properties of a range’s Borders collection. For example, the macro…
- Input Box in Excel VBA: Use InputBox and Get DataIn Excel VBA, use InputBox to ask for a text value, or Application.InputBox when you want to restrict the response to a…
- Import Multiple Files Using VBA in Excel: A Practical GuideYes. In Excel for Microsoft 365 on Windows, VBA can loop through files in a selected folder, open each one, and copy…
- Excel VBA UserForm Data Entry: Build a Simple FormTo enter data through an Excel VBA UserForm, create a form with text boxes and a Save button, validate the entries in…
- Add Comments in Excel VBA: Notes and Threaded CommentsTo add a cell note with Excel VBA, select the cell and run ActiveCell.AddComment "Check this value." in a macro; Excel calls…
- Outlook VBA: Pull Email Data into ExcelTo pull email data from Outlook into Excel, run a VBA macro in Excel that connects to classic Outlook, reads messages in…
- VBA Resize Pictures to Fit in Excel Cells AutomaticallyTo resize pictures to fit inside Excel cells with VBA, run a macro that finds each picture, scales it proportionally to the…
- VBA Dictionary Key Count: How to Use the Count PropertyTo count the keys in a VBA dictionary, read its Count property: dict.Count. It returns the number of key-item pairs currently stored,…
- Excel VBA Scroll Bar Form Control: Setup, Uses, and CodeIn Excel for Microsoft 365 on Windows, insert a Form Control scroll bar from Developer > Insert > Form Controls, then link…
- VBA Excel Send Email in New Outlook: Options That WorkNot directly: Excel VBA’s traditional Outlook automation uses the Outlook COM object model, which New Outlook for Windows does not support. To…
- Set Image Height in Excel VBA Using InchesTo set an image to a height measured in inches, assign its VBA Height property the result of Application.InchesToPoints. For example, pic.Height…
- Excel VBA to List File Names in All Subfolders AutomaticallyTo list file names from a folder and all its subfolders in Excel for Microsoft 365 on Windows, run a VBA macro…
- VBA Outlook Create Contact Group from ExcelYes. In classic Outlook for Windows, an Excel VBA macro can read email addresses from a worksheet, create an Outlook contact group…
- Excel VBA Data Entry Form With a Picture Box: How It WorksYes. In Excel for Microsoft 365 on Windows, make a VBA UserForm, add an Image control to act as the picture box,…
- How to Put a Photo in a VBA UserFormTo put a photo in an Excel VBA UserForm, add an Image control, then either set its Picture property in the form…
- Excel UserForm Combo Box: Add, Populate, and Use ItAn Excel UserForm combo box is a VBA control that lets someone choose an item from a drop-down list, and in some…
- Excel VBA: Save a Sheet as a Web Page with FormattingYes. In desktop Excel for Microsoft 365 on Windows, VBA can publish one worksheet as a static HTML web page while retaining…
- Excel VBA: Match a Trendline Label to Its Line ColorYes. In Excel VBA, set the trendline label’s font color to the trendline’s line color: use Trendline.DataLabel.Font.Color and Trendline.Format.Line.ForeColor.RGB. The macro below…
- Create a Pivot Table in Excel Using VBATo create a PivotTable with VBA, prepare a rectangular data range with clear headers, then use a PivotCache and CreatePivotTable in a…
- How to Delete Blank Rows in Excel with a VBA MacroTo delete blank rows in Excel with a macro, select the data range, run a VBA procedure that checks each selected row,…
- Excel SUBSTITUTE in VBA: Replace or WorksheetFunctionTo substitute text in Excel VBA, use VBA’s built-in Replace function; it replaces every matching occurrence by default. To replace only a…
- Vba loop through rows?Learn how to loop through Excel rows with VBA, find the last row, handle conditions and deletions, and avoid common macro mistakes.