+ Reply to Thread
Results 1 to 6 of 6

Help with managing data. Complicated one!

  1. #1
    Registered User
    Join Date
    05-02-2007
    Posts
    17

    Help with managing data. Complicated one!

    I'm new to macros and am trying something way above me here so any help appreciated!
    I have a list of runners in a horse race as seen below. I need a macro to basically scan down the list and make sure there are exactly 3 horses listed in each race.
    If 4 or more horses show I need to delete the bottom ones and if only 1 or 2 show I need to add rows to make sure there are 3 rows for that race.
    As below you will see that the 2.10 race needs the bottom horse taken out as it has 4 horses in it and the 2.35 has only 2 so I need it to enter a blank like below it.

    Any ideas anyone!?!?!?!?

    If you need the spreadsheet I've attached the data as a text file.

    Runners Track Time Horse Rating
    13 NOTT 2.00 EXPENSIVE ART 87
    13 NOTT 2.00 BERTIE SWIFT 76
    13 NOTT 2.00 WELSH AUCTION 61
    8 ASCO 2.10 FAT BOY 97
    8 ASCO 2.10 MOUNT PLEASURE 95
    8 ASCO 2.10 THUNDER BAY 81
    8 ASCO 2.10 SAUZE D'OULX 81 <------ Delete this one as too many
    9 PONT 2.20 CEE BARGARA 92
    9 PONT 2.20 IRVING PLACE 74
    9 PONT 2.20 BARRALAND 70
    10 NOTT 2.35 NOBILISSIMA 76
    10 NOTT 2.35 ELLCON 66
    5 ASCO 2.45 SILVER PIVOTAL 88 <------ Add a blank here as needs to be 3 lines in each race
    5 ASCO 2.45 ITALIAN GIRL 72
    5 ASCO 2.45 FRETWORK 68
    9 PONT 2.55 OFFICER 76
    9 PONT 2.55 BINOCULAR 68
    9 PONT 2.55 RANAVALONA 61
    9 PONT 2.55 EL DECECY 61

    Thanks in advance for helping out a newb!
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    01-05-2004
    Location
    Helsinki, Finland
    Posts
    100
    Hi,

    Assuming that your table starts from A1 and the first line contains the headers (Runners, Track, Time, Horse, Rating) and there are no empty lines in the data, this should work:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-02-2007
    Posts
    17
    Hi Jazzer,

    You sir are a genious!!!!!!!

    That worked a treat and has saved me loads of time.

    Question?
    Is there a way to make it only process the first 300 rows? There is only ever about 250-280 rows of data and the macro goes on for ages which I assume is the script checking the whole workbook.

    Thanks again!

  4. #4
    Forum Contributor
    Join Date
    01-05-2004
    Location
    Helsinki, Finland
    Posts
    100
    Hi and thank you :D

    The ending of this line:

    For lRow = 3 To Range("C1").End(xlDown).Row

    after the "To", searches the last line of the sheet and uses it as the ending point of the loop. You can just write there the last line you want to check, like this:

    For lRow = 3 To 300

    That goes throug the first 300 lines.

    - Asser

  5. #5
    Registered User
    Join Date
    05-02-2007
    Posts
    17
    Hi,

    I tried that but it still just keeps going. I let it run for about 2 minutes and it was still churning away.

    It doesn't matter really though as I can just hit escape and stop the script.

    Thank for all your help.

  6. #6
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    maybe this macro can help, different flavor same result
    Please Login or Register  to view this content.
    Denis

    Please always attach the sample workbook without sensitive information when asking for help

    To add a module
    Press Alt + F11 (this is the Visual Basic Environment)
    Insert Menu, select Module
    Past code there
    Close Visual Basic Environment (X)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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