Results 1 to 5 of 5

Consolidating Code

Threaded View

  1. #1
    Registered User
    Join Date
    08-09-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Consolidating Code

    Hello,

    I run a NFL pool with a bunch of my friends from a spreadsheet. I use it as a tool to help me learn new tricks and methods in excel (learning is so much more fun when its not what you get paid to do).

    Anyway two years ago I started using a Macro for the scoring and I was hoping to simplify the code. Essentially its a matrix and the macro just compares what is populated in the field where they make their pick to a field that is populated with the winner of the game, then makes the appropriate changes. As I was/am new at this I went the brute force method. The core of the code is below:

    Sub Scoring()
    
    If Pick = Winner And Pick = Bonus Then
        Pick.Select
        With Selection.Interior
        .ColorIndex = 4
        Pick.Select
        Selection.Font.ColorIndex = 0
        ScorePos.Value = 1
        BonusPos.Value = 1
    End With
    ElseIf Pick = Winner Then
        Pick.Select
        With Selection.Interior
        .ColorIndex = 35
        Pick.Select
        Selection.Font.ColorIndex = 0
        ScorePos.Value = 1
        End With
    Else: Pick.Select
        With Selection.Interior
        .ColorIndex = 45
        Pick.Select
        Selection.Font.ColorIndex = 0
    End With
    End If
    
    End Sub
    
    Sub Week01()
    
    Set Pick = Range("H3")
    Set Winner = Range("F3")
    Set Bonus = Range("D3")
    Set ScorePos = Range("AH3")
    Set BonusPos = Range("BH3")
    Scoring
    
    Set Pick = Range("H4")
    Set Winner = Range("F4")
    Set Bonus = Range("D4")
    Set ScorePos = Range("AH4")
    Set BonusPos = Range("BH4")
    Scoring

    (more of this ad nauseam)

    The 'setting' piece repeats 192 times per week (16 games * 12 players) and I have a different macro for each week. As you can imagine this makes for a very long string of code. Due to the repetitive nature I am assuming that there must be another way to do this but Google has failed to provide me much help.

    Any help would be greatly appreciated.

    Thank you,
    Nik
    Last edited by NRZ; 08-09-2010 at 04:05 PM.

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