Join Curt Frye for an in-depth discussion in this video Stepping through all items of a collection using a For...Each loop, part of Learning VBA in Excel.
The Excel object model groups objects of the same type into collections;…for example, the Workbook object contains the Worksheets collection, which…contains a Worksheet object for each worksheet in the workbook;…in fact, if you go up one level the application object contains the Workbooks…collection, which in turn contains a Workbook object for each open workbook.…If you want your code to affect every member of a collection or an array, you…don't have to count the number of items in the collection and work through them one by one;…instead, you can use a For Each Loop to interact with every element in the…array or the collection.…
As an example, let's take a look at the code I have here.…In this example, I have an array of strings, which are the names of cities to…which Two Trees has shipped products within a given month.…In this case, I can use a For Each Loop, as shown here, to move through each…element within the array and display its value.…There are a couple of things you need to keep in mind when you're working with…
- Working in the Visual Basic Editor
- Adding code to a macro
- Creating, exporting, and deleting code modules
- Declaring and using variables
- Managing variable scope
- Defining arrays
- Managing workbooks and worksheets with VBA
- Repeating tasks with loops
- Debugging VBA code
- Cutting, copying, and pasting cell data
- Running and triggering event procedures
Skill Level Advanced
Excel 2010: Tips, Tricks, and Shortcutswith Dennis Taylor3h 43m Intermediate
1. Introducing Visual Basic for Applications (VBA)
2. Defining Variables, Constants, and Calculations
3. Adding Logic to Your VBA Code
4. Debugging Your VBA Code
5. Managing Workbook Elements and Data in VBA
6. Adding Advanced Elements to Your Workbook
7. Using Excel Events in Your VBA Code
8. Putting It All Together
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.