+ Reply to Thread
Results 1 to 11 of 11

assigning variables in consecutive order

  1. #1
    Registered User
    Join Date
    12-06-2008
    Location
    miami
    Posts
    9

    assigning variables in consecutive order

    I appreciate anyone looking at this post and offering help.
    It's kind of hard to explain what I'm actually looking for but here it goes.

    I have a spreadsheet that contains multiple named records, see below example,

    HARPER
    HARPER
    MCKINLEY
    HARPER
    HARPER
    HARPER
    HARPER
    HARPER
    HARPER
    HARPER
    HARPER
    HARPER
    HARPER
    LINCOLN
    MCKINLEY
    MCKINLEY
    ADAMS
    ADAMS
    GRIFFITH
    GRIFFITH
    GRIFFITH
    ADAMS
    ADAMS
    ADAMS
    GARFIELD
    GARFIELD
    GARFIELD
    GARFIELD
    GARFIELD
    GARFIELD
    GARFIELD
    GRIFFITH

    I am trying to assign a sequential variable each time a new name appears(assuming we going from top to bottom). not neccessary a variable for each record, but for each unique different record.

    in other words:
    From the example above, there would be 6 unique variables, (a,b,c,d,e,f)
    a=Harper
    b=Mckinley
    c=Lincoln
    d=Adams
    e=Griffith
    f=Garfield

    and then ultimately I would like to data sort by grouping the same occurances of names, but following the order that they first appear.

    Thank you again, for looking at this post and trying to help.
    Last edited by alexramo; 12-06-2008 at 06:57 PM. Reason: grammer problem

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Probably easiest to do with a dictionary.

    Post a workbook?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-06-2008
    Location
    miami
    Posts
    9
    what do you mean by dictionary?
    I didn't post a workbook, because I thought it would be easier to just copy and paste that example data set into an excel workbook.
    thank you for taking a crack at this!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    ... because I thought it would be easier to just copy and paste that example data set into an excel workbook
    Paste it where?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Please Login or Register  to view this content.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello alexramo,

    From your post I gather you're looking for an example workbook. The attached workbook has a button on Sheet1 to run the macro. When the macro runs, Sheet2 is cleared, except for row 1 and the groups are copied in the order they are found with their Sheet1 addresses beside them. You will probably want to do something else. This is to demonstrate how the disparate cells (non contiguous) can be regrouped into a contiguous range for sorting later. Here is the macro code...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-06-2008
    Location
    miami
    Posts
    9

    Thank you

    Everbody, thank you for replying to this post.
    Leith I have another question, and I aplogize before hand, for not including this in the original post, but if I had another column with numbers, corresponding to a house #, (as those names were actually streets), how would you go about sorting it by consecutive order, after you put the array into the sequential order that you had solved?
    for instance,

    145 HARPER
    142 HARPER
    200 MCKINLEY
    139 HARPER
    138 HARPER
    137 HARPER
    135 HARPER
    134 HARPER
    132 HARPER
    131 HARPER
    130 HARPER
    121 HARPER
    111 HARPER
    4448 LINCOLN
    212 MCKINLEY
    221 MCKINLEY
    40 ADAMS
    43 ADAMS
    7770 GRIFFITH
    7772 GRIFFITH
    7778 GRIFFITH
    39 ADAMS
    38 ADAMS
    21 ADAMS
    3252 GARFIELD
    3245 GARFIELD
    3232 GARFIELD
    3221 GARFIELD
    3233 GARFIELD
    3234 GARFIELD
    3235 GARFIELD
    7769 GRIFFITH

    I actually thought the code would be easier to understand(i am obviously not an expert!) and I would be able to add that extra sorting function, but I see that your solution, and also SHG's solution is way beyond my knowledge base.

    Great work by the way, I'm going to do some research today and try to figure out how you did some of that coding, it's amazing. thank you again.
    -alex

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Alex,

    I updated the macro. Column "A" contains the houde number and "B" the street name. Each group is sorted in ascending order once is has been transferred to the second worksheet. The attached workbook has the macro added. Here is the code...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-06-2008
    Location
    miami
    Posts
    9

    Couldn't get it to work

    Hello Leith,
    Thank you again for helping on this issue.
    Unfortunately, when I opened the workbook and ran the macro, it didn't change the order at all, in fact it was a replica of the array on tab1.

    I know I might not have made sense when I was explaining the sorting method, so below is an example of what it should look like:

    11 HARPER
    12 HARPER
    17 HARPER
    24 HARPER
    53 HARPER
    54 HARPER
    60 HARPER
    66 HARPER
    68 HARPER
    80 HARPER
    157 HARPER
    202 HARPER
    121 MCKINLEY
    230 MCKINLEY
    870 MCKINLEY
    515 LINCOLN
    1209 ADAMS
    3005 ADAMS
    3921 ADAMS
    4100 ADAMS
    4405 ADAMS
    72 GRIFFITH
    1801 GRIFFITH
    1980 GRIFFITH
    2200 GRIFFITH
    40 GARFIELD
    58 GARFIELD
    65 GARFIELD
    87 GARFIELD
    95 GARFIELD
    99 GARFIELD
    100 GARFIELD

    Notice that it is in the order that it originally appreared(i grabbed it from the results of your first macro), and then also sorted in ascending order, based on the house address. Is this possible?
    Thank you again for your help,
    -alex

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Alex,

    Sorry about that, this version is correct. I was working on the program while helping my daughter balance her checkbook. Couldn't see the forest for trees. This version is correct and already added to the attached wowrksheet.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    12-06-2008
    Location
    miami
    Posts
    9

    Thank you!

    Leith, thank you it works great, you might think I'm easily impressed, but I think it's amazing!

    I appreciate all your help, and everyone that took a crack at it.
    Take care,
    -Alex

+ 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