Help me on median vba please

ftnzul

New Member
Joined
May 28, 2015
Messages
1
im trying to sorting the data into ascending order then calculate the median. but im having trouble when sorting it into ascending order. can you look at my code :

Dim x As Integer, j As Integer, t As Integer
Dim median As Single
Dim num(0 To 100) As Integer
Dim order(0 To 100) As Integer
Dim count As Integer

row = 3

Do
num(t) = Val(Sheet1.Cells(row + t, 2))

t = t + 1
count = count + 1
Loop While Sheet1.Cells(row + t, 2) <> ""

For j = 0 To count

For t = j To count

If num(j) < num(t) Then
order(j) = num(t)
Else
order(j) = num(t + 1)
End If

Next t
Next j
row = 12

For t = 0 To count
Sheet1.Cells(row + t, 2) = order(t)
Next t


so the problem is at the for t = j to count, the if else is wrong and i dont know how to fix it already.can someone please help me
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
have you tried starting the macro recorder then running sort into the order you want, let excel do what it can, as for median it is already a fuction and dosen't need a sorted list
 
Upvote 0

Forum statistics

Threads
1,216,115
Messages
6,128,923
Members
449,479
Latest member
nana abanyin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top