LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default UDF Sort Function

Not a UDF< event code

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A:A" '<== change to suit
Dim LastRow As Long
Dim i As Long

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

With Target

Me.Columns(1).Sort key1:=Me.Range("A1"), _
order1:=xlAscending, _
header:=False

LastRow = Me.Cells(Me.Rows.Count, .Column).End(xlUp).Row
For i = LastRow To 1 Step -1

If Me.Cells(i, .Column).Value = Me.Cells(i - 1,
..Column).Value Then

Me.Rows(i).Delete
End If
Next i
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"luvnrocs" wrote in message
...
Hi -

I need a UDF that can sort a column of text and weed out duplicates.
If the weeding of duplicates is not possible I'll just take the sort
function. I can't use Excel's sort function because I need the sort to
happen dynamically when the user enters text in column A. Some cells
in column A could be blank.

Col A contains text strings like
GGG
BBB
<blank
CCC
AAA
FFF
<blank
BBB
GGG
<blank
HHH
AAA
LLL

so with the proper UDF Column B would look like this
AAA
BBB
CCC
FFF
GGG
HHH
LLL


Any help would be greatly appreciated!



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sort function for dates does not sort properly in Office 2007 Exc. Rosalie Excel Worksheet Functions 1 November 22nd 07 10:25 PM
Sort : how can I use a variable in a VB sort function? El Bee Excel Worksheet Functions 3 February 16th 06 09:34 PM
sort function to sort for bell curve Kuby Excel Discussion (Misc queries) 4 December 16th 05 06:51 PM
Complicated sort function with sort and sum Matz Excel Worksheet Functions 3 August 29th 05 07:50 AM
Excel Sort function should not sort the cell formatting! Lisa D.N.1 Excel Worksheet Functions 1 December 28th 04 08:37 PM


All times are GMT +1. The time now is 06:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"