Page 169 - Excel Progamming Weekend Crash Course
P. 169

k540629 ch11.qxd  9/2/03  9:34 AM  Page 144




                144                                                       Saturday Afternoon


               Listing 11-1                                                      Continued
                              largest_value = r.Cells(row, col).Value
                          End If
                          If r.Cells(row, col).Value < smallest_value Then
                  smallest_value = r.Cells(row, col).Value
                          End If
                      Next col
                  Next row

                  s = “The largest and smallest values are “
                  s = s & largest_value & “ and “ & smallest_value
                  MsgBox s

                  End Sub

































                    Figure 11-1 The output of the program in Listing 11-1
                  To see this program in action, complete the following steps:

                 1. Enter the code from the listing into the VBA Editor.
                 2. Switch to Excel, and enter numerical values in all cells of a range in the
                    worksheet.
                 3. Select the range by dragging over it with the mouse.
                 4. Run the program from the macros dialog box (Alt+F8).
   164   165   166   167   168   169   170   171   172   173   174