![]() ![]() What the macro doesn't do is to show how to select a variable number of cells to be summed. ![]() While this particular macro may not be that useful, it shows several helpful techniques, such as how to define a named range, how to use the SUM function, and how to stuff the sum into a cell. ![]() The results of the first run are put in B1, the second in B2, and the third in B3. It then uses the SUM worksheet function to assign the sum to the Results variable, which is (finally) stuffed into a cell in column B. Next loop to specify different ranges of cells to be summed. All you need to do is to preface the function name with "Application.WorksheetFunction." or simply "WorksheetFunction." Thus, if you know that each run of the macro will require summing A1:A100, then A1:A300, and finally A1:A25, you could use a macro like this: The problem is that the number of cells to be summed will vary for one run of the macro it could be 100 cells, while on the next it could be 300 and on the third only 25.įirst, it is easy to use most worksheet functions (such as SUM) from within a macro. Bob has a need to use the SUM function in a macro in order to find the sum of all the values in a column. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |