11 articles VBA Macro

How to Loop Through Worksheets in a Workbook in Excel VBA?

Using the For Each Loop The code below loops through all worksheets in the workbook, and activates each worksheet. The code uses the “for each” loop to loop through the wrosheets contained inside ThisWorkbook. After it is done looping through all the worksheets, it reactivates the original worksheet that was active before running the macro.…

How to type on the keyboard in VBA?

You can use VBA to automatically “type” characters (and numbers) on the keyboard. In addition, it can also perform keyboard actions, such as Control+C (copy), Control+A (select all), Alt+Tab, etc. (See examples below) Almost anything that can be done on the keyboard is possible through VBA. This is very useful as you can automate many…

How to Loop Through All Cells and Multiple Ranges in VBA?

The “.Areas.Count” property has the number of areas stored in a Range object. You can loop through the “.Areas” in a Range object to access each of the areas in a range individually. This ability is very handy on subroutines or functions designed to perform actions on all cells a user selected, because this accounts for any number of areas a…