Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 271
Default Finding all unique values

I have a table of data in sheet2 in rows A:F.

I would like a VBA that would search through these rows and list the unique
values only in sheet1 column A

Please help and thanks in advance


--
Thanks
Shawn
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Finding all unique values

Hi Shawn,

Try:

'================================
Public Sub Tester03()
Dim Col As Collection
Dim Arr() As Variant
Dim rCell As Range
Dim rng As Range
Dim i As Long
Dim WB As Workbook
Dim sh1 As Worksheet
Dim Sh2 As Worksheet

Set WB = ActiveWorkbook
Set sh1 = WB.Sheets("Sheet2")
Set Sh2 = WB.Sheets("Sheet1")
Set Col = New Collection
Set rng = sh1.Columns("A:F")

Application.ScreenUpdating = False

For Each rCell In rng.Cells
If Not IsEmpty(rCell.Value) Then
On Error Resume Next
Col.Add rCell.Value, CStr(rCell.Value)
On Error GoTo 0
End If
Next rCell
On Error Resume Next
ReDim Arr(1 To Col.Count)

For i = LBound(Arr, 1) To UBound(Arr, 1)
Arr(i) = Col.Item(i)
Next i

Sh2.Range("A1").Resize(i - 1) = Application.Transpose(Arr)

Application.ScreenUpdating = True

End Sub
'================================


---
Regards,
Norman



"Shawn" wrote in message
...
I have a table of data in sheet2 in rows A:F.

I would like a VBA that would search through these rows and list the
unique
values only in sheet1 column A

Please help and thanks in advance


--
Thanks
Shawn



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Finding all unique values

norman,

use a scripting dictionary iso a collection.
you gain speed as you can directly retrieve the dictionary's
items array iso recreating it as you must with a collection.

added benefit, you can make it case sensitive

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Norman Jones wrote :

Hi Shawn,

Try:

'================================
Public Sub Tester03()
Dim Col As Collection
Dim Arr() As Variant
Dim rCell As Range
Dim rng As Range
Dim i As Long
Dim WB As Workbook
Dim sh1 As Worksheet
Dim Sh2 As Worksheet

Set WB = ActiveWorkbook
Set sh1 = WB.Sheets("Sheet2")
Set Sh2 = WB.Sheets("Sheet1")
Set Col = New Collection
Set rng = sh1.Columns("A:F")

Application.ScreenUpdating = False

For Each rCell In rng.Cells
If Not IsEmpty(rCell.Value) Then
On Error Resume Next
Col.Add rCell.Value, CStr(rCell.Value)
On Error GoTo 0
End If
Next rCell
On Error Resume Next
ReDim Arr(1 To Col.Count)

For i = LBound(Arr, 1) To UBound(Arr, 1)
Arr(i) = Col.Item(i)
Next i

Sh2.Range("A1").Resize(i - 1) = Application.Transpose(Arr)

Application.ScreenUpdating = True

End Sub
'================================


---
Regards,
Norman



"Shawn" wrote in message
...
I have a table of data in sheet2 in rows A:F.

I would like a VBA that would search through these rows and list
the unique values only in sheet1 column A

Please help and thanks in advance


-- Thanks
Shawn

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Finding all unique values

Hi Jurgen,

Good suggestion!


---
Regards,
Norman



"keepITcool" wrote in message
.com...
norman,

use a scripting dictionary iso a collection.
you gain speed as you can directly retrieve the dictionary's
items array iso recreating it as you must with a collection.

added benefit, you can make it case sensitive

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Norman Jones wrote :

Hi Shawn,

Try:

'================================
Public Sub Tester03()
Dim Col As Collection
Dim Arr() As Variant
Dim rCell As Range
Dim rng As Range
Dim i As Long
Dim WB As Workbook
Dim sh1 As Worksheet
Dim Sh2 As Worksheet

Set WB = ActiveWorkbook
Set sh1 = WB.Sheets("Sheet2")
Set Sh2 = WB.Sheets("Sheet1")
Set Col = New Collection
Set rng = sh1.Columns("A:F")

Application.ScreenUpdating = False

For Each rCell In rng.Cells
If Not IsEmpty(rCell.Value) Then
On Error Resume Next
Col.Add rCell.Value, CStr(rCell.Value)
On Error GoTo 0
End If
Next rCell
On Error Resume Next
ReDim Arr(1 To Col.Count)

For i = LBound(Arr, 1) To UBound(Arr, 1)
Arr(i) = Col.Item(i)
Next i

Sh2.Range("A1").Resize(i - 1) = Application.Transpose(Arr)

Application.ScreenUpdating = True

End Sub
'================================


---
Regards,
Norman



"Shawn" wrote in message
...
I have a table of data in sheet2 in rows A:F.

I would like a VBA that would search through these rows and list
the unique values only in sheet1 column A

Please help and thanks in advance


-- Thanks
Shawn



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
finding unique values waylonk Excel Discussion (Misc queries) 2 May 3rd 10 09:40 PM
Finding unique values with Criterias dolpphinv4 Excel Discussion (Misc queries) 1 April 14th 05 02:37 AM
Finding Unique Values in Column Kirk P. Excel Discussion (Misc queries) 1 January 25th 05 02:01 PM
Need help finding unique values and transforming an n x 1 Array Marston Excel Programming 3 August 12th 04 07:34 PM
Finding Unique Values from Multiple Columns Disco[_3_] Excel Programming 1 October 7th 03 03:20 PM


All times are GMT +1. The time now is 08:29 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"