Results 1 to 2 of 2

condensing long if's based on same numbers (loop)

Threaded View

Squirrel condensing long if's based on... 09-12-2011, 03:34 PM
Squirrel Re: condensing long if's... 09-13-2011, 10:00 AM
  1. #1
    Registered User
    Join Date
    01-24-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    31

    condensing long if's based on same numbers (loop)

    Code first:
    If 6 > Me.cmbShiftNumber.Value >= 1 Then
        .Cells(3, 1).Value = Me.cmbS1T1.Value
        .Cells(3, 3).Value = Me.cmbS1T2.Value
        If Me.cmbPpl1.Value > 0 Then
        .Cells(4, 1).Value = "1)"
        End If
        
        If Me.cmbPpl1.Value > 1 Then
        .Cells(4, 3).Value = "2)"
        End If
        
        If Me.cmbPpl1.Value > 2 Then
        .Cells(5, 1).Value = "3)"
        End If
        
        If Me.cmbPpl1.Value > 3 Then
        .Cells(5, 3).Value = "4)"
        End If
        
        If Me.cmbPpl1.Value > 4 Then
        .Cells(6, 1).Value = "5)"
        End If
    'etc
    
    Else
        .Cells(3, 1).Value = Me.cmbS1T1.Value
        .Cells(3, 2).Value = Me.cmbS1T2.Value
        If Me.cmbPpl1.Value > 0 Then
        .Cells(4, 1).Value = "1)"
        End If
        
        If Me.cmbPpl1.Value > 2 Then
        .Cells(4, 2).Value = "2)"
        End If
    'etc
    End If
    As you can see this is a repetitive if formula.

    It is based off of combo boxes names cmbS1T1-cmbS10T2
    Then for each there is cmbPpl1-14

    The usage is the start time and end time of each shift. (S = shift) (T = 1 for start, 2 for end)

    The cmbPpl are how many people will be at each shift 1-14


    If you look at the above code you will see the cells it is going into. Same repetitions as above.


    The only difference is that if there are less than 6, it should use the entire box and if more than 6 it will split the 4 cells wide box in half and use the first half for shift 1 and the second shift would be in the smaller box to the right it just split to.

    Examples are included in the attached excel document.

    Any questions please ask.

    I am just looking for a condensed loop formula of some sort that would do this before I spend 4 hours writing it all out. I am sure there is a better way.

    Thanks.
    Attached Files Attached Files

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