Sorting the results of a formula alphabetically

liampog

Active Member
Joined
Aug 3, 2010
Messages
316
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi there

In Cells A2:A1001 there are customer full names - first and last name and any middle names (example: John James Smith)

In Cells B2:B1001 there are the membership numbers of the customers

In Cells C2:C1001 I have the following equations which extract the last name of the customers so I can sort by last name:

Code:
=IF(A2<>"",RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2," ","*",LEN(A2)-LEN(SUBSTITUTE(A2," ",""))))),"")

I have a Worksheet_Change event that monitors when the membership number is entered and then sorts all the names by the surname (column C).

However, it is sorting all the names in alphabetical order but moving them to the bottom of the range ending at Row 1001.

I think it's because the sort command is sorting the actual formulas rather than the results of the formulas.

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

    Application.ScreenUpdating = False
    
    If Not Intersect(Target, Columns("B")) Is Nothing Then
        ActiveSheet.Unprotect
        Range("A2:C1001").Sort Key1:=Range("C1"), Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
        ActiveSheet.Protect
    End If

    Application.ScreenUpdating = True

End Sub

Is there any way to fix the sorting code so that it sorts the actual results of the formulas rather than the formulas themselves.

I have my reasons for having the customer's full name in one cell rather than splitting them into columns for First, Middle and Last Names.... that being that I have the name column set up as a named range which I then refer to from another sheet to create a dropdown Data Validation selection cell.

Thanks in advance,
Liam
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top