LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default List unique items

I'm trying to look at a works sheet and list all the unique items
found on that sheet in another sheet. The source sheet has around 50
columns of varying length. The following codes was slightly modified
from http://www.ozgrid.com/forum/showthread.php?t=39790 which comes
close to doing what I need. I need the area analyzed to be dynamic so
I added counting the used columns and rows (nCol and nRow) and tried
to work them into the code. the column count was pretty easy to work
in but the row count which seems to correspond to the upper bound of
"y" is not responding well to my attempts. Part of the problem is my
ignorance of the dictionary script thing that is implemented in the
code.

Any help will be appreciated.

Sub test()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim dic As Object, w, y
Dim a, i As Long
Dim nCol As Integer
Dim nRows As Integer

Set dic = CreateObject("Scripting.Dictionary")
Set ws1 = Sheets("List") ' alter if needed


With ws1.Range("a1").CurrentRegion
a = .Value
End With

nCol = ws1.UsedRange.Columns.Count
nRows = ws1.UsedRange.Rows.Count


For i = LBound(a, 1) To UBound(a, 1)
If Not IsEmpty(a(i, 1)) Then
If Not dic.exists(a(i, 1)) Then
ReDim w(1 To nCol)
For ii = 1 To nCol
w(ii) = a(i, ii)
Next
dic.Add a(i, 1), w
Else
w = dic(a(i, 1)): w(nCol) = Val(w(nCol)) + Val(a(i,
nCol))
dic(a(i, 1)) = w
End If
End If
Next
y = dic.items: Set dic = Nothing
On Error Resume Next
Set ws2 = Sheets("Summary")
If ws2 Is Nothing Then
Set ws2 = Sheets.Add
ws2.Name = ("Summary")
End If
On Error GoTo 0
With ws2.Range("a1")
.CurrentRegion.ClearContents
With .Range("a1")
For i = LBound(y) To UBound(y)
.Offset(i).Resize(, UBound(y(i))) = y(i)
Next
End With
End With
Set ws1 = Nothing: Set ws2 = Nothing
Erase a, y, w
End Sub
 
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
tagging unique items in a list K. Gwynn Excel Worksheet Functions 7 June 16th 06 02:20 PM
Unique Items in Drp-down List Chris Hankin Excel Programming 8 May 16th 04 12:24 PM
VBA to get List of Unique Items from column Stuart[_5_] Excel Programming 1 September 24th 03 01:57 PM
VBA to get List of Unique Items from column Bob Phillips[_5_] Excel Programming 0 September 23rd 03 08:34 PM
VBA to get List of Unique Items from column Jim Rech Excel Programming 0 September 23rd 03 08:30 PM


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

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"