Thread
:
ummm, ummm, HELP!!!
View Single Post
#
9
Posted to microsoft.public.excel.misc
CWillis
external usenet poster
Posts: 36
ummm, ummm, HELP!!!
Sorry about the late reply. Just got back from vacation. Could you give me
a better description of the problem? Data-Sort-Descending should sort 123...
I'm assuming your problem is more complex. Sample data and a goal would be
best.
-Chris
"Curt" wrote:
trying to sort consectlive 12345678 have entries in column D scrambled as
come in. Need to sort final as 12345678 from complete sheet. Can this be done?
Thanks
"CWillis" wrote:
Well, I ran out of time so it isn't finished, but it seems to work with the
data you gave me.
Quick explanation:
Finds the center of the circle (this is the biggest problem. It currently
finds the center by averaging all x's and all y's. This is fine as long as
the points are nicely distributed around the circle. This will cause a
problem if most points are on one side for example.) After it finds the
center, it finds the angle of the imaginary line between the center and the
actual point. Using the angle, you can sort the data points so they come out
nice and neat when you plot them.
Here is what you need to do:
On a worksheet named "AutoSort", in row 1 starting with cell one, but the
following titles:
X Value
Y Value
xdelta
ydelta
theta (degrees)
alt+f11 takes you into the vba screen. Paste the following code:
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''
Option Explicit
sub testing()
'Private Sub CommandButton1_Click()
Dim numpoints As Integer
Dim xsum
Dim ysum
Dim xaverage
Dim yaverage
Dim xdelta
Dim ydelta
Dim degadd As Integer
Dim i As Integer
Dim pi
'num points
Sheets("AutoSort").Range("A2").Select 'select first point
Selection.End(xlDown).Select 'get last point
numpoints = ActiveCell.Row - 1 'gets num points
'averages (current way of finding center of circle)
For i = 1 To numpoints
xsum = xsum + Sheets("autosort").Cells(i + 1, 1).Value
ysum = ysum + Sheets("autosort").Cells(i + 1, 2).Value
Next i
xaverage = xsum / numpoints
yaverage = ysum / numpoints
'xdelta and ydelta
For i = 1 To numpoints
Sheets("autosort").Cells(i + 1, 3).Value =
Sheets("autosort").Cells(i + 1, 1).Value - xaverage
Sheets("autosort").Cells(i + 1, 4).Value =
Sheets("autosort").Cells(i + 1, 2).Value - yaverage
Next i
'theta in degrees
pi = 4 * Atn(1) ' Calculate the value of pi.
For i = 1 To numpoints
xdelta = Sheets("autosort").Cells(i + 1, 3)
ydelta = Sheets("autosort").Cells(i + 1, 4)
'depending on quadrant, may have to add degrees
If xdelta 0 Then
If ydelta < 0 Then degadd = 360
End If
If xdelta < 0 Then degadd = 180
'display degree amount
Sheets("autosort").Cells(i + 1, 5).Value = degadd + Atn(ydelta /
xdelta) * 180 / pi
'Sheets("autosort").Cells(i + 1, 5).Value = Atn(ydelta / xdelta) *
180 / pi
Next i
End Sub
''''''''''''''''''''''''''''''''''''''''''''''
(You can make a button to run this if you so choose and then just uncomment
the second line.) Now, paste your data points under x value and y value and
run the code. It will display numbers under your column "theta (degrees)".
Now, go to data, sort and sort by "theta (degrees)". Your plot should work
when you plot the x and y values now.
Post any questions. I will be able to help on Monday.
Hope that helps.
-Chris
"phattony72" wrote:
Yeah, I know that a simple sort won't do it. I'm trying to think of
anything else that can be done.
I've included my sample set as a txt file (easy to open with excel,
just comma delimited). It's ok with this one because there are only a
few points, but I will have others with thousands of points. You'll
notice that the two LINE sets form vague circles (if you do a simple
x-y scatter you can see this).
Thanks.
+-------------------------------------------------------------------+
|Filename: T1_2_outlines.txt |
|Download:
http://www.excelforum.com/attachment.php?postid=5221
|
+-------------------------------------------------------------------+
--
phattony72
------------------------------------------------------------------------
phattony72's Profile:
http://www.excelforum.com/member.php...o&userid=37662
View this thread:
http://www.excelforum.com/showthread...hreadid=572700
Reply With Quote
CWillis
View Public Profile
Find all posts by CWillis