View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default Sorted range into collection

Sub Macro1()


Dim lLastRow As Long
Dim lLastCol As Long
Dim i As Long
Dim j As Long
Dim k As Long

Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select


lLastRow = ActiveSheet.UsedRange.Rows.Count - 1
lLastCol = ActiveSheet.UsedRange.Columns.Count - 1
For i = 0 To lLastRow - 1
For j = lLastRow To i + 1 Step -1
For k = 0 To lLastCol
If ActiveSheet.Range("A1").Offset(i, k).Value <
ActiveSheet.Range("A1").Offset(j, k).Value Then
Exit For
End If
Next k
If k lLastCol Then
ActiveSheet.Range("A1").Offset(j, 0).EntireRow.Delete
End If
Next j
Next i

End Sub

Before you run this code, make a backup of your data in case it does
something you don't expect!!

HTH,
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"mm_it_it" wrote:

Hi everyone,
I'm working with excel 2003 and I'm developing a custom interface to
automatize some operations.
I'm using the MS office VB editor. I can't use .net framework.
I need to:
- take the values contained in an excel column
- sort values alphabetically
- remove duplicate values
- put the values in a collection.
I need to do everything "on the code side", cell values on the sheet cannot
be modified.
The requisite of the collection is not mandatory, any similar object would
be useful.
I did many test but none of them works.
Thanks in advance to everybody

--
Nobody expects the Spanish Inquisition! Our chief weapon is
surprise...surprise and fear...fear and surprise.... Our two weapons are fear
and surprise...