The code below enables sorting particular columns through a macro: Sub sb_VBA_Sort_Data_descending() Range("A1:H20").Sort _ Key1:=Range("H1"), Order1:=xlDescending End Sub Consider the table below. The goal is to have the data sorted by column H and in a descending order. Note that:
It is possible to link the macro to a button or it could be programmed in a way that the table automatically get sorted every time it is opened regardless of how it was last saved when it was closed. To achieve this all we need to do is to create a “Private Sub” and insert the code above within the private sub: Private Sub Workbook_Open() Sub sb_VBA_Sort_Data_descending() Range("A1:H10").Sort _ Key1:=Range("H1"), Order1:=xlDescending End Sub End Sub
0 Comments
Leave a Reply. |
CategoriesArchives
June 2020
|