Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Is a Collection the best option?

I could be wrong, but I think that collections are groups of variables or
objects, not values.
(I have made collections of form controls to simulate control arrays in VB6
in Excel VBA.)

What you may need is a dynamic array. Declare it with empty parentheses and
redim it when you add an item. Use the keyword Preserve to avoid erasing
the data in the array. That works well for 1 dimensional arrays, but if you
need a two or more column array, it gets kinda hairy.

In your code, substitute Dim EnquiryList() as Variant in the declarations.

Then sub

ReDim Preserve EnquiryList(1 to Ubound(EnquiryList)+1) 'expand array
size by one
EnquiryList(Ubound(EnquiryList)) = Cell.Value 'put
unique value in array

for EnquiryList.Add Cell.Value

If you just want to add these unique values to a list box in a form, use the
additem method and don't bother with the array.

ListBox1.AddItem Cell.Value

Hope this helps.

"Stuart" wrote in message
...
I'm looking to take unique values from a defined range
into a form. The values will be alphabetic characters.
Here is what I have so far:

Sub SortContractorsSuppliers()

Dim ws As Worksheet, LastRow As Long
Dim DataRange As Range, Cell As Range
Dim EnquiryList As New Collection

For Each ws In ActiveWorkbook.Worksheets
With ws
.Unprotect
LastRow = Application.Max(.Range("H65536") _
.End(xlUp).Row, .Range("I65536").End(xlUp).Row, _
.Range("J65536").End(xlUp).Row)
Set DataRange = Range("H2", "J" & LastRow)
On Error Resume Next
For Each Cell In DataRange
If Not IsEmpty(Cell) Then
EnquiryList.Add Cell.Value
End If
Next Cell
On Error GoTo 0
End With
Next

MsgBox EnquiryList

End Sub

Why is it that when the code loops into the 2nd sheet, any
unique values in that sheet's DataRange are not added to the
Collection, please?

Regards.





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 19/08/2003




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Is a Collection the best option?

Ugh. Looks like my comments got wrapped in that code.

Use this:

Dim EnquiryList() as Variant

ReDim Preserve EnquiryList(1 to Ubound(EnquiryList)+1)
EnquiryList(Ubound(EnquiryList)) = Cell.Value

The comments aren't necessary.


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
Dont have secondary axis option listed in Series Option Venus Charts and Charting in Excel 3 February 23rd 10 07:30 PM
preserve formatting option in pivot table option dialog box Dave F Excel Discussion (Misc queries) 4 May 8th 08 07:25 PM
keep source formatting is not an option in paste option button Tina Excel Discussion (Misc queries) 0 February 20th 06 09:58 PM
Reformat IF(ISERROR(....) : if 1st option returns empty, look at 2nd option. sonar Excel Worksheet Functions 3 September 12th 05 09:52 PM
Sum textboxes in a collection Mark[_18_] Excel Programming 1 August 28th 03 04:17 AM


All times are GMT +1. The time now is 12:55 AM.

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"