Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Display unique values in a range.

I am looking for a procedure that will

loop through items in a range, and return the unique items starting in
a target cell.

Range 1
2
2
2
3
4
5
3
4


Range 2
2
3
4
5


such that when I run the macro each item in Range 1 is looked at until
Range 1 =" ". The result being Range 2.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Display unique values in a range.

Here's a simple macro to do this

Dim cLastRow As Long
Dim i As Long
Dim j As Long
Dim prevVal

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
prevVal = ""
For i = 1 To cLastRow
If Cells(i, "A").Value < prevVal Then
j = j + 1
Cells(j, "B").Value = Cells(i, "A").Value
prevVal = Cells(i, "A").Value
End If
Next i

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"future" wrote in message
om...
I am looking for a procedure that will

loop through items in a range, and return the unique items starting in
a target cell.

Range 1
2
2
2
3
4
5
3
4


Range 2
2
3
4
5


such that when I run the macro each item in Range 1 is looked at until
Range 1 =" ". The result being Range 2.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 303
Default Display unique values in a range.

Or you could go to <data<filter<advanced filter select "copy to another
place" and
tick "unique records."

regards
Bill K

"Bob Phillips" wrote in message
...
Here's a simple macro to do this

Dim cLastRow As Long
Dim i As Long
Dim j As Long
Dim prevVal

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
prevVal = ""
For i = 1 To cLastRow
If Cells(i, "A").Value < prevVal Then
j = j + 1
Cells(j, "B").Value = Cells(i, "A").Value
prevVal = Cells(i, "A").Value
End If
Next i

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"future" wrote in message
om...
I am looking for a procedure that will

loop through items in a range, and return the unique items starting in
a target cell.

Range 1
2
2
2
3
4
5
3
4


Range 2
2
3
4
5


such that when I run the macro each item in Range 1 is looked at until
Range 1 =" ". The result being Range 2.





  #4   Report Post  
Posted to microsoft.public.excel.programming
m m m m is offline
external usenet poster
 
Posts: 4
Default Display unique values in a range.

I want the copy to range to be on a separate sheet. Is it possible to
change "B" to be a target cell on another sheet?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Display unique values in a range.

this code only looks to see if a value is unique to its previous value.

any way to see if it is unique to all previous values?

Sub Unique()
Dim cLastRow As Long
Dim i As Long
Dim j As Long
Dim prevVal

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
prevVal = ""
For i = 1 To cLastRow
If Cells(i, "A").Value < prevVal Then
j = j + 1
Cells(j, "B").Value = Cells(i, "A").Value
prevVal = Cells(i, "A").Value
End If
Next i
End Sub


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Display unique values in a range.

Try this

Sub Unique()
Dim cLastRow As Long
Dim i As Long
Dim j As Long
Dim prevVal
Dim c As Range

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
prevVal = ""
For i = 1 To cLastRow
Set c = Worksheets("Sheet2").Columns("B").Find(Cells(i, "A"))
If c Is Nothing Then
j = j + 1
Worksheets("Sheet2").Cells(j, "B").Value = Cells(i, "A").Value
prevVal = Cells(i, "A").Value
End If
Next i

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"future" wrote in message
om...
this code only looks to see if a value is unique to its previous value.

any way to see if it is unique to all previous values?

Sub Unique()
Dim cLastRow As Long
Dim i As Long
Dim j As Long
Dim prevVal

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
prevVal = ""
For i = 1 To cLastRow
If Cells(i, "A").Value < prevVal Then
j = j + 1
Cells(j, "B").Value = Cells(i, "A").Value
prevVal = Cells(i, "A").Value
End If
Next i
End Sub



Reply
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
Display only unique values in CONCATENATE formula Mally Excel Discussion (Misc queries) 4 March 21st 09 07:30 PM
Display Unique Values S Davis Excel Worksheet Functions 4 August 4th 06 10:45 PM
Display Unique Values Question carl Excel Worksheet Functions 1 June 2nd 06 06:34 AM
count and display unique values joe Excel Worksheet Functions 2 December 19th 05 01:11 AM
Modifying a Formula To display only Unique Values carl Excel Worksheet Functions 1 April 16th 05 08:17 PM


All times are GMT +1. The time now is 11:28 PM.

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

About Us

"It's about Microsoft Excel"