+ Reply to Thread
Results 1 to 3 of 3

Sort Xvalues and rearrange Yvalues

  1. #1
    Registered User
    Join Date
    08-31-2011
    Location
    Tokyo
    MS-Off Ver
    Excel 2010
    Posts
    50

    Question Sort Xvalues and rearrange Yvalues

    Hello,

    I don't know if it is the correct forum but I need help for charting correctly.
    I have 2 arrays X and Y.
    I use the following code in order to chart :
    .SeriesCollection(1).Values = Y
    .SeriesCollection(1).XValues = X
    My problem is the Xvalues are not in ascending order, is it possible to sort it quickly and change the Y array the same way ?
    For example :
    X = [10 , 2 , 1 , 3 , 1]
    Y = [100, 200 , 300, 400, 500]
    I would like the following results :
    Xsort = [1 , 1 , 2 , 3 , 10]
    Ysort = [ 300, 500 , 200, 400, 100]

    Is there some kind of option in Excel or do I have to sort using VBA ?
    It is kind of tricky because the Xvalues can have doubles and do not correspond to the same Y values.

    Thank you in advance.
    Last edited by oro77; 01-22-2013 at 02:18 AM. Reason: SOLVED

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Sort Xvalues and rearrange Yvalues

    I would suggest that is the x-values are in a column and the y-values are in the next one record the sorting action of the range and run it before you graph it.

  3. #3
    Registered User
    Join Date
    08-31-2011
    Location
    Tokyo
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Sort Xvalues and rearrange Yvalues

    Do you mean to put the data in the column of a sheet ?
    How do I do the sorting action ?

    Thank you in advance.

    EDIT :
    Thanks to your advise, I solve my problem.
    The method I was looking for :
    Worksheets(Sheetname).Range(RangeValue).Sort Key1:=Worksheets(Sheetname).Cells(v1, v2), order1:=xlAscending
    Last edited by oro77; 01-22-2013 at 02:17 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1