Page 234 - Trackpad 402_Class-X_Final
P. 234
Sorting the Column Using a Macro
Sorting means arranging the data in the ascending or descending order. To sort data in a spreadsheet select the range
of cells and click on Data → Sort.
These steps to sort a specific range of cells can be stored in a macro. So that next time if you wish to sort the data
in any of the worksheets you just have to run the macro and the sorting will be done automatically. Take care that
the range of cells used at the time of creating a macro are matching with the range of cells you wish to sort using
a macro. For example, you created the macro for range B5:B20 will cover 16 consecutive cells. So at the time of
using the macro total 16 consecutive cells should be selected to run the macro otherwise it will not work and data
will not be sorted.
Let us take the example of the given name of the cites to be sorted in the ascending order by creating a macro as
shown below:
Step 1: Create a worksheet with the given list of the cities in cell C4:C20.
Step 2: Select the range B4:B20.
Step 3: Click on Tools menu and select Macros option, click on Record Macro.
Step 4: Click on Data menu and select Sort option, click on Sort By -Name → Ascending
Step 5: Click on OK button.
Step 6: Click on Stop Recording.
Step 7: Specify the name for this new macro as -SORTMACRO_EXAMPLE.
Step 8: Click on Save button.
Step 9: Now select Sheet 2 and enter any 15 numbers in random order.
Step 10: Click on Tools menu and select Macros option. Click on Run Macro in the sub menu that appear. Choose the
name of the saved macro.
Step 11: Click on Run button.
Macro will be executed and the numbers are sorted in the ascending order.
234 Trackpad Information Technology-X

