Help with Excel

Copper Contributor

Hello,

I have downloaded an excel spreadsheet from google docs.

In one column, are the names of people alphabetized.  The other columns are the names of their club and another column is the town they live in.  How do I set up the spreadsheet (now saved to my computer) so that if I click on any of these columns, the entire data will rearrange/alphabetized to the column I have selected?  I have only been able to find out how to alphabetize a column but then just that column, (not all the columns) rearranges.   One row of information is data of one person that needs to stay intact.  Thank you! 

2 Replies

@NPRenae 

Hi

Before applying any sort to your list, make sure of:

  1. Your columns have headers
  2. You have Blanks all around your list
  3. No blank columns in between
  4. You select one SINGLE Cell in the column that will be the primary sort.
  5. Do not select the Entire Column.

Accordingly Excel will resize the selection and sorts All the records based upon the column you specified.

clipboard_image_0.png

 

When you select a Single cell in the column you want (Name or Club or Town) you can sort by:

  • Click on Sort & Filter to the right side of the Home Tab
  • Right click and Sort
  • Click on Ascending or Descending on the Data Tab
  • Use the Shortcuts for ascending or descending:  ALT, A S A   or ALT, A S D

I attached a Sample File

Good Luck

Nabil Mourad

 

 

@NPRenae 

You may use VBA to automate the Data Sorting so that whenever you select a column header, the data will be sorted in Ascending order in the column of the selected header.

 

It's always a best practice to add an Index column so that you can return to the original state of data by sorting the Index column at any time.

 

The attached file contains a Selection Change Event to sort the data automatically once you select a column header.

 

I have added an Index column which can be sorted to get back the data in it's original state. If you don't need the Index column, you can delete that column.

 

The following code is placed on the Sheet1 Module.

To implement the code to your original workbook, follow these steps...

 

  1. Open your File.
  2. Right click on Sheet Tab and choose View Code.
  3. Paste the code given below into the opened code window.
  4. Close the VB editor.
  5. Save your Workbook either as .xlsm, .xls or .xlsb i.e. a file format which supports Macros in it.

Let me know if this is something you can work with.

 

Code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("A1").CurrentRegion.Rows(1)) Is Nothing Then
    ActiveSheet.Sort.SortFields.Clear
    Range("A1").CurrentRegion.Sort key1:=Target.Offset(1, 0), order1:=xlAscending, Header:=xlYes
End If
End Sub