-
Hi,
Welcome to VBAX
An array doesn't have countable rows in that fashion
try
[VBA]
Function Sorting(vector1 As Variant)
Dim n, k, i, j As Integer
Dim temp As Variant
n = UBound(vector1)
ReDim temp(1 To n, 1 To 3)
For j = 1 To n
k = n
For i = 1 To n
If (Abs(vector1(j, 3))) > (Abs(vector1(i, 3))) Then
k = k - 1
End If
Next i
temp(k, 1) = vector1(j, 1)
temp(k, 2) = vector1(j, 2)
temp(k, 3) = vector1(j, 3)
Next j
Sorting = temp
End Function
[/VBA]
or, If you are getting data from a range
[VBA]
Sub DoSort()
Dim arr As Range
Set arr = Range("Data")
Rws = arr.Rows.Count
Cells(10, 1).Resize(Rws, 3) = Sorting(arr)
End Sub
Function Sorting(vector1 As Variant)
Dim n, k, i, j As Integer
Dim temp As Variant
n = vector1.Rows.Count
ReDim temp(1 To n, 1 To 3)
For j = 1 To n
k = n
For i = 1 To n
If (Abs(vector1(j, 3))) > (Abs(vector1(i, 3))) Then
k = k - 1
End If
Next i
temp(k, 1) = vector1(j, 1)
temp(k, 2) = vector1(j, 2)
temp(k, 3) = vector1(j, 3)
Next j
Sorting = temp
End Function
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules