Re: Sorting a variant array
- From: "Peter T" <peter_t@discussions>
- Date: Mon, 15 Oct 2007 22:20:31 +0100
Hi George,
tempList = Range(ThisWorkbook.Names.Item(rangeName).RefersTo)
(which btw you could write as
tempList = ThisWorkbook.Range(rangeName).Value
assuming you really do mean ThisWorkbook and not ActiveWorkbook (if not
same) and assuming rangeName refers to a range, etc
Anyway, the point is tempList will become a 2D array, even if its one column
or one row. That means when you want to refer to it elements you will need
to do
tempList(i, 1) ' cells down column 1
tempList (1, i) ' cells accross row 1
I don't follow why you need to convert to strings.
Regards,
Peter T
"George" <George@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:88FFA71A-EDA6-4786-BA95-345A69AAEFDA@xxxxxxxxxxxxxxxx
Having a problem sorting my variant array which I'm hoping someone will besorting
able to assist me with. I'm positive it's something I'm doing as the
algorithim I'm using works in all the examples supplied with the routine -at
it's the one from MS :-)
The complete code I've got at the moment (including my pathetic attempts
Debug.Print to find out why it's not working is below):be
Dim tempList() As Variant
Dim testerList() As String
Function sortTesters(rangeName As String)
Application.Volatile
' check if the input name exists
If nameExists(rangeName) Then
' retrieve the named range
'Set namedRange = ThisWorkbook.Names.Item(rangeName)
' read the named range into an array
tempList = Range(ThisWorkbook.Names.Item(rangeName).RefersTo)
Debug.Print UBound(tempList)
For Each tester In tempList
Debug.Print tester ' ***1***
Next
Dim i As Integer
For i = LBound(tempList) To UBound(tempList)
testerList(i) = tempList(i)
Debug.Print testerList(i) ' ***2***
Next i
'Call BubbleSort(testerList)
End If
End Function
I've commented out the BubbleSort call at the moment because I can't even
move the Variant array into a String array which is what I thought might
causing the problem. The ***1*** debug line prints out all the staff oneby
one in the same order that's in the Range. This works fine, however when I(i
try and move them (one by one) to a string array I get no debug output and
presume) the routine falls over and exits.gives
Even if I don't try the movement to a String Array the sorting algorithm
doesn't do anything with the variant array. If I put a debug line in the
sorting algorithm to output the number of items in the passed array it
me the correct reading but as soon as it tries to "do something" with anyno
value in the array it must bomb out - there's no further debug output and
error message.output)
I'm at a bit of a loss as to what is happening here - the sorting code is
fine (as I say trying it with the examples supplied gives me correct
so it must be something stupid that I've done.
Any pointers gratefully taken :-)
George
.
- References:
- Sorting a variant array
- From: George
- Sorting a variant array
- Prev by Date: Re: Create New Workbook and add VBA Code to using VBA
- Next by Date: embedded Word document
- Previous by thread: Re: Sorting a variant array
- Next by thread: How to make sub handle more than 1 cell ?
- Index(es):
Relevant Pages
|