![]() ThisWorkbook.Worksheets(i).Cells(1, 1) = 1 'this sets cell A1 of each sheet to "1"įor most intents and purposes, both methods can achieve the same result of looping through all worksheets. You can use the for loop to access worksheets by calling “ThisWorkbook.Worksheet(i)”, with “i” being the number. ![]() The first worksheet is 1, second is 2, third is 3, etc. Basically each worksheet can be accessed by a number. Starting_ws.Activate 'activate the worksheet that was originally activeĪn alternative approach, instead of using the “For each” loop, and going through each worksheet in the ThisWorkbooko object, is to use the For loop. Ws.Cells(1, 1) = 1 'this sets cell A1 of each sheet to "1" Set starting_ws = ActiveSheet 'remember which worksheet is active in the beginning The comments highlight how the “re-activation” is done.įor the sake of an example on how to access each worksheet, the macro also sets cell A1 of each worksheet to “1”. After it is done looping through all the worksheets, it reactivates the original worksheet that was active before running the macro. The code uses the “for each” loop to loop through the wrosheets contained inside ThisWorkbook. The code below loops through all worksheets in the workbook, and activates each worksheet.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |