+ Reply to Thread
Results 1 to 25 of 25

'Compile Error - Procedure Too Large'

Hybrid View

nods 'Compile Error - Procedure... 11-08-2010, 02:27 PM
blane245 Re: 'Compile Error -... 11-08-2010, 03:21 PM
nods Re: 'Compile Error -... 11-08-2010, 04:19 PM
blane245 Re: 'Compile Error -... 11-08-2010, 04:28 PM
nods Re: 'Compile Error -... 11-08-2010, 04:50 PM
blane245 Re: 'Compile Error -... 11-08-2010, 04:53 PM
nods Re: 'Compile Error -... 11-08-2010, 05:10 PM
nods Re: 'Compile Error -... 11-08-2010, 05:29 PM
shg Re: 'Compile Error -... 11-08-2010, 07:59 PM
nods Re: 'Compile Error -... 11-08-2010, 08:13 PM
shg Re: 'Compile Error -... 11-08-2010, 08:28 PM
nods Re: 'Compile Error -... 11-08-2010, 08:50 PM
shg Re: 'Compile Error -... 11-09-2010, 11:29 AM
nods Re: 'Compile Error -... 11-10-2010, 01:18 PM
nods Re: 'Compile Error -... 11-10-2010, 01:25 PM
shg Re: 'Compile Error -... 11-10-2010, 02:01 PM
nods Re: 'Compile Error -... 11-10-2010, 05:47 PM
nods Re: 'Compile Error -... 11-10-2010, 06:01 PM
shg Re: 'Compile Error -... 11-10-2010, 06:10 PM
snb Re: 'Compile Error -... 11-10-2010, 06:35 PM
nods Re: 'Compile Error -... 11-10-2010, 06:39 PM
nods Re: 'Compile Error -... 11-10-2010, 07:00 PM
nods Re: 'Compile Error -... 11-10-2010, 08:18 PM
shg Re: 'Compile Error -... 11-10-2010, 08:29 PM
nods Re: 'Compile Error -... 11-11-2010, 12:44 AM
  1. #1
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    'Compile Error - Procedure Too Large'

    I have a rota input form that has 30 lines of input enabling the user to add 30 members of staff at a time. The form is designed with the staff names down the left and start and finish time drop downs for each day of the week acrross the right. The staff name is only entered once for each week even the work all 7 days.

    I wrote the below code which works fine for one line of the rota form, but when I replicate it 30 times I get a 'Compile Error - Procedure Too Large'.

    Is there a way of breaking the code up or using a loop to replicate the code?

    The following input fields increase in value by 1 for each line.

    TeamMbr1
    DayStart1
    DayFinish1

    The following inout fields are static because they are only selected once at the top of the form.

    WeekDD2.
    SiteDD2
    DeptDD2

    The full code is attached
    ..
    Private Sub RunBtn_Click()
    
    If WeekDD2.Value = "Select Week" Or SiteDD2.Value = "Select Site" Or DeptDD2.Value = "Team/Dept" Then
    
      MsgBox "Please Select a Site,Week and Department", vbExclamation, "Error"
    
    Exit Sub
    
    End If
    
    If TeamMbr1.Value = "Team Mbr" Or FriStart1.Value = "Start" Or FriFinish1.Value = "Finish" Then
    GoTo Saturday01
    Exit Sub
    
    End If
    
    Sheets("Rota Input").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0) = Me.WeekDD2.Value
    
    Sheets("Rota").Range("G2").Value = Me.WeekDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "I").End(xlUp).Offset(1, 0) = "Friday"
       
    Sheets("Rota Input").Cells(Rows.Count, "J").End(xlUp).Offset(1, 0) = Me.SiteDD2.Value
    
    Sheets("Rota").Range("C2").Value = Me.SiteDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0) = Me.DeptDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "L").End(xlUp).Offset(1, 0) = Me.TeamMbr1.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "M").End(xlUp).Offset(1, 0) = Me.FriStart1.Text
    
    Sheets("Rota Input").Cells(Rows.Count, "N").End(xlUp).Offset(1, 0) = Me.FriFinish1.Value
    
    
    
    Saturday01:
    
    If TeamMbr1.Value = "Team Mbr" Or SatStart1.Value = "Start" Or SatFinish1.Value = "Finish" Then
    GoTo Sunday01
    
    Exit Sub
    
    End If
    
    Sheets("Rota Input").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0) = Me.WeekDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "I").End(xlUp).Offset(1, 0) = "Saturday"
       
    Sheets("Rota Input").Cells(Rows.Count, "J").End(xlUp).Offset(1, 0) = Me.SiteDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0) = Me.DeptDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "L").End(xlUp).Offset(1, 0) = Me.TeamMbr1.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "M").End(xlUp).Offset(1, 0) = Me.SatStart1.Text
    
    Sheets("Rota Input").Cells(Rows.Count, "N").End(xlUp).Offset(1, 0) = Me.SatFinish1.Value
    
    
    
    Sunday01:
    
    If TeamMbr1.Value = "Team Mbr" Or SunStart1.Value = "Start" Or SunFinish1.Value = "Finish" Then
    GoTo Monday01
    
    Exit Sub
    
    End If
    
    
    Sheets("Rota Input").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0) = Me.WeekDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "I").End(xlUp).Offset(1, 0) = "Sunday"
       
    Sheets("Rota Input").Cells(Rows.Count, "J").End(xlUp).Offset(1, 0) = Me.SiteDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0) = Me.DeptDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "L").End(xlUp).Offset(1, 0) = Me.TeamMbr1.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "M").End(xlUp).Offset(1, 0) = Me.SunStart1.Text
    
    Sheets("Rota Input").Cells(Rows.Count, "N").End(xlUp).Offset(1, 0) = Me.SunFinish1.Value
    
    
    
    Monday01:
    
    If TeamMbr1.Value = "Team Mbr" Or MonStart1.Value = "Start" Or MonFinish1.Value = "Finish" Then
    GoTo Tuesday01
    
    Exit Sub
    
    End If
    
    
    
    Sheets("Rota Input").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0) = Me.WeekDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "I").End(xlUp).Offset(1, 0) = "Monday"
       
    Sheets("Rota Input").Cells(Rows.Count, "J").End(xlUp).Offset(1, 0) = Me.SiteDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0) = Me.DeptDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "L").End(xlUp).Offset(1, 0) = Me.TeamMbr1.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "M").End(xlUp).Offset(1, 0) = Me.MonStart1.Text
    
    Sheets("Rota Input").Cells(Rows.Count, "N").End(xlUp).Offset(1, 0) = Me.MonFinish1.Value
    
    
    Tuesday01:
    
    If TeamMbr1.Value = "Team Mbr" Or TuesStart1.Value = "Start" Or TuesFinish1.Value = "Finish" Then
    GoTo Wednesday01
    
    Exit Sub
    
    End If
    
    
    Sheets("Rota Input").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0) = Me.WeekDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "I").End(xlUp).Offset(1, 0) = "Tuesday"
       
    Sheets("Rota Input").Cells(Rows.Count, "J").End(xlUp).Offset(1, 0) = Me.SiteDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0) = Me.DeptDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "L").End(xlUp).Offset(1, 0) = Me.TeamMbr1.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "M").End(xlUp).Offset(1, 0) = Me.TuesStart1.Text
    
    Sheets("Rota Input").Cells(Rows.Count, "N").End(xlUp).Offset(1, 0) = Me.TuesFinish1.Value
    
    
    
    Wednesday01:
    
    If TeamMbr1.Value = "Team Mbr" Or WedStart1.Value = "Start" Or WedFinish1.Value = "Finish" Then
    GoTo Thursday01
    
    Exit Sub
    
    End If
    
    
    
    Sheets("Rota Input").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0) = Me.WeekDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "I").End(xlUp).Offset(1, 0) = "Wednesday"
       
    Sheets("Rota Input").Cells(Rows.Count, "J").End(xlUp).Offset(1, 0) = Me.SiteDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0) = Me.DeptDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "L").End(xlUp).Offset(1, 0) = Me.TeamMbr1.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "M").End(xlUp).Offset(1, 0) = Me.WedStart1.Text
    
    Sheets("Rota Input").Cells(Rows.Count, "N").End(xlUp).Offset(1, 0) = Me.WedFinish1.Value
    
    
    
    Thursday01:
    
    If TeamMbr1.Value = "Team Mbr" Or ThursStart1.Value = "Start" Or ThursFinish1.Value = "Finish" Then
    GoTo Friday02
    
    Exit Sub
    
    End If
    
    
    
    Sheets("Rota Input").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0) = Me.WeekDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "I").End(xlUp).Offset(1, 0) = "Thursday"
       
    Sheets("Rota Input").Cells(Rows.Count, "J").End(xlUp).Offset(1, 0) = Me.SiteDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0) = Me.DeptDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "L").End(xlUp).Offset(1, 0) = Me.TeamMbr1.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "M").End(xlUp).Offset(1, 0) = Me.ThursStart1.Text
    
    Sheets("Rota Input").Cells(Rows.Count, "N").End(xlUp).Offset(1, 0) = Me.ThursFinish1.Value
    Attached Files Attached Files
    Last edited by nods; 11-11-2010 at 12:45 AM.

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: 'Compile Error - Procedure Too Large'

    There are more concise ways to code this, but a simple solution would be to take all of your code in the sub and move it to a sub called, say, TeamMember1, then call that routine from Run_Btn_Click. Then you can replicate TeamMember1 the required number of times calling them TemMember2 ..., , change the variable names as appropriate in each and then call each one from Run_Btn_Click.
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  3. #3
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    Ok thank you. I checked with just 5 employees and the code ran fine. So I broke the code up into segments of 5 and called the subs:

    TeamMember1-5
    TeamMember6-10
    TeamMember11-15
    TeamMember16-20
    TeamMember21-25
    TeamMember26-30

    I have 2 questions.

    Have done this correctly? New code attached. and how do i now get my button to run all 6 subs as one?

    many thanks

    Nods
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: 'Compile Error - Procedure Too Large'

    Private Sub RunBtn_Click()
    
    TeamMember1to5
    TeamMember6to10
    TeamMember11to15
    TeamMember16to20
    TeamMember21to25
    TeamMember26to30
    
    End Sub

  5. #5
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    Many thanks once again. sorry for the questions but this is my first vba project.

    Just one more question. I get complie errors on the lables that are split between to subs for example:

    If TeamMbr5.Value = "Team Mbr" Or ThursStart5.Value = "Start" Or ThursFinish5.Value = "Finish" Then
    GoTo Friday06
    
    Exit Sub
    
    End If
    
    
    
    Sheets("Rota Input").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0) = Me.WeekDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "I").End(xlUp).Offset(1, 0) = "Thursday"
       
    Sheets("Rota Input").Cells(Rows.Count, "J").End(xlUp).Offset(1, 0) = Me.SiteDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0) = Me.DeptDD2.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "L").End(xlUp).Offset(1, 0) = Me.TeamMbr5.Value
    
    Sheets("Rota Input").Cells(Rows.Count, "M").End(xlUp).Offset(1, 0) = Me.ThursStart5.Text
    
    Sheets("Rota Input").Cells(Rows.Count, "N").End(xlUp).Offset(1, 0) = Me.ThursFinish5.Value
    
    End Sub
    
    
    Sub TeamMember6to10()
    
    
    Friday06:

    Is there a way of solving this. it is an integral part of the form to prevent unneccesary data being written to the wookbook?

    many thanks

    nods

  6. #6
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: 'Compile Error - Procedure Too Large'

    Looks lioke were making good progress. Since you moved all of the code to separate modules, the use of "Me" may not be clear to VBA. Change all of them to the name of our UserForm that contains the button and see if that helps.

  7. #7
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    Really sorry but i'm not following you! Not sure what you mean.

  8. #8
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    is it possible to have a



    Then 
    
    
    Go to Sub Name
    Statment I tried a few things and it didnt seem to work.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 'Compile Error - Procedure Too Large'

    I think (I have no way to test) that your 5500 lines of code can be replaced with something like this:

    Option Explicit
    
    Private Sub RunBtn_Click()
        Dim vDay        As Variant
        Dim sDay        As String
        Dim iCnt        As Long
    
        If WeekDD2.Value = "Select Week" Or SiteDD2.Value = "Select Site" Or DeptDD2.Value = "Team/Dept" Then
            MsgBox "Please Select a Site, Week, and Department", vbExclamation, "Error"
            Exit Sub
        End If
    
        For iCnt = 1 To 30
            For Each vDay In Array("Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday")
                sDay = Left(vDay, 3)
                If TeamMbr1.Value <> "Team Mbr" And _
                   Me.Controls(sDay & "Start1").Value <> "Start" And _
                   Me.Controls(sDay & "Finish1").Value <> "Finish" Then
    
                    RotaOut Array(Me.WeekDD2.Value, _
                                  vDay, _
                                  Me.SiteDD2.Value, _
                                  Me.DeptDD2.Value, _
                                  Me.TeamMbr1.Value, _
                                  Me.Controls(sDay & "Start1").Text, _
                                  Me.Controls(sDay & "Finish1").Value)
    
                    If vDay = "Friday" Then
                        Sheets("Rota").Range("G2").Value = Me.WeekDD2.Value
                        Sheets("Rota").Range("C2").Value = Me.SiteDD2.Value
                    End If
                End If
            Next vDay
        Next iCnt
    
        Worksheets("Rota Input").Calculate
        Worksheets("Rota Tables").Calculate
        Worksheets("Rota").Calculate
        Worksheets("Overview").Calculate
        Worksheets("Rota").Select
    End Sub
    
    Sub RotaOut(v As Variant)
        Worksheets("Rota Input").Cells(Rows.Count, "H").End(xlUp)(2).Resize(, UBound(v) + 1).Value = v
    End Sub
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    many thanks I was feeling a lil proud of that code aswel but your code much more user friendly.

    Just 1 problem I get the 'Can not find specified object error' on

    If TeamMbr1.Value <> "Team Mbr" And _
                  Me.Controls(sDay & "Start1").Value <> "Start" And _
                  Me.Controls(sDay & "Finish1").Value = "Finish" Then
    Any ideas?

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 'Compile Error - Procedure Too Large'

    Change the code to ...
                If TeamMbr1.Value <> "Team Mbr" And _
                   Me.Controls(sDay & "Start" & iCnt).Value <> "Start" And _
                   Me.Controls(sDay & "Finish" & iCnt).Value <> "Finish" Then
    
                    RotaOut Array(Me.WeekDD2.Value, _
                                  vDay, _
                                  Me.SiteDD2.Value, _
                                  Me.DeptDD2.Value, _
                                  Me.TeamMbr1.Value, _
                                  Me.Controls(sDay & "Start" & iCnt).Text, _
                                  Me.Controls(sDay & "Finish" & iCnt).Value)
    However, you're still going to need to learn to debug code. See http://www.cpearson.com/excel/Debug.htm
    Last edited by shg; 11-08-2010 at 08:33 PM. Reason: extra line slipped in

  12. #12
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    Hi thanks for your help. I am checking the debug tutorial you sent. Thank you very much btw.

    I cant see why I am getting the can not find object error.

    I am trying to attach the file but I keep getting an error message.

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 'Compile Error - Procedure Too Large'

    So when the code breaks, in the Immediate window, enter

    ? sDay & "Start" & iCnt

    Does that return the correct name for a control?

    What about the next one?

  14. #14
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    Really sorry not sure waht you mean? Where do I type this?

  15. #15
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    the obeject names are:

    DAYStart1 - DAYStart30
    DAYFinish1 - DAYFinish30
    TeamMbr1 - TeamMbr30

    The DAY is replaced with Mon, Tues , Wed, Thurs , Fri , Sat and Sun

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 'Compile Error - Procedure Too Large'

    Really sorry not sure waht you mean? Where do I type this?
    In the Immediate window in the VBE. Do Ctrl+G to see it if it's not already visible.

    Me.Controls is a collection. So in the Immediate window, when the code is at a breakpoint in the form module, you should be able to enter

    ? Me.Controls("MonStart30").Value

    to see the value of that control.

    This construct:

    Me.Controls(sDay & "Start" & iCnt)

    ... synthesizes the name of a control from from two variables and a literal string. So when the code is stopped at some point when those variables are all initialized, you enter

    ? sDay & "Start" & iCnt

    and see if the control name is valid, and

    ? Me.Controls(sDay & "Start" & iCnt).Value

    to see the value of that control.

    I would urge to to spend an hour reading Chip's tutorial about debugging, and then come back to ask any further questions.

  17. #17
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    many thanks.

    The problem was the array was assuming my 'Day' object labels always had 3 letters. this isnt the case because i used Thurs and Tues.

    I amended the code and now works fine.

    new code for information is :

    Private Sub RunBtn_Click()
    
        Dim vDay        As Variant
        Dim sDay        As String
        Dim iCnt        As Long
    
        If WeekDD2.Value = "Select Week" Or SiteDD2.Value = "Select Site" Or DeptDD2.Value = "Team/Dept" Then
            MsgBox "Please Select a Site, Week, and Department", vbExclamation, "Error"
            Exit Sub
        End If
                Sheets("Rota").Range("G2").Value = Me.WeekDD2.Value
                Sheets("Rota").Range("C2").Value = Me.SiteDD2.Value
        
        For iCnt = 1 To 30
            
            For Each vDay In Array("Fri", "Sat", "Sun", "Mon", "Tues", "Wed", "Thurs")
              
             sDay = (vDay)
                
                If TeamMbr1.Value <> "Team Mbr" And _
                   Me.Controls(sDay & "Start" & iCnt).Value <> "Start" And _
                   Me.Controls(sDay & "Finish" & iCnt).Value <> "Finish" Then
    
                    RotaOut Array(Me.WeekDD2.Value, _
                                  vDay, _
                                  Me.SiteDD2.Value, _
                                  Me.DeptDD2.Value, _
                                  Me.TeamMbr1.Value, _
                                  Me.Controls(sDay & "Start" & iCnt).Text, _
                                  Me.Controls(sDay & "Finish" & iCnt).Value)
                                  
                    If vDay = "Friday" Then
                       
    
                 End If
                End If
            
            Next vDay
            
        Next iCnt
    
        Worksheets("Rota Input").Calculate
        Worksheets("Rota Tables").Calculate
        Worksheets("Rota").Calculate
        Worksheets("Overview").Calculate
        Worksheets("Rota").Select
        MsgBox "Saved.", vbInformation
    End Sub

  18. #18
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    However...

    I tried applying the same principles to another crazy 5000 line peice of code that I wrote and I'm not sure where I am goin wrong. The code is used to amend the data that is written to the workbook in the above code. So should be similar.

    I am getting the 'invalid Next control Variable reference' error on the

    Next iCnt
    Line

    Can you see where I have gone wrong? This is my first attempt at arrays in VBA.

    Many thanks

    Nods

    An example workbook attached.

    New code

    Dim varSite As String
    Dim varWeek As String
    Dim varTeam As String
    Dim varWS As Worksheet
    Dim varLastRow As Long
    Dim varRow As Long
    Dim vDay As Variant
    Dim sDay As Variant
    Dim iCnt As Long
    
    
    Application.ScreenUpdating = False
    
    varSite = Me.SiteDD2.Value
    varWeek = Me.WeekDD2.Value
    varTeam = Me.DeptDD2.Value
    
    Set varWS = Sheets("Rota Input")
    varLastRow = varWS.Range("A50000").End(xlUp).Row
    
    For iCnt = 1 To 30
            
            For Each sDay In Array("Fri", "Sat", "Sun", "Mon", "Tues", "Wed", "Thurs")
              
             For Each vDay In Array("Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday")
                
                If TeamMbr1.Value <> "Team Mbr" And _
                   Me.Controls(sDay & "Start" & iCnt).Value <> "Start" And _
                   Me.Controls(sDay & "Finish" & iCnt).Value <> "Finish" Then
    
    For varRow = 2 To varLastRow
    
        If varWS.Cells(varRow, 2).Value = varWeek Then
           If varWS.Cells(varRow, 4).Value = varSite Then
            If varWS.Cells(varRow, 5).Value = varTeam Then
            Select Case varWS.Cells(varRow, 1).Value
    
                    Case Me.WeekDD2.Value + sDay + Me.SiteDD2.Value + Me.DeptDD2.Value + iCnt
                    
                    varWS.Cells(varRow, 12).Value = Me.Controls(TeamMbr & iCnt).Value
                    varWS.Cells(varRow, 13).Value = Me.Controls(sDay & "Start" & iCnt).Value
                    varWS.Cells(varRow, 14).Value = Me.Controls(sDay & "Finish" & iCnt).Value
    
    
    
    End Select
            End If
          End If
          End If
          
         
    Next iCnt
    Next vDay
    Next sDay
    
    End If
        
        Sheets("Rota").Range("G2").Value = Me.WeekDD2.Value
          Sheets("Rota").Range("C2").Value = Me.SiteDD2.Value
          
          End If
          
     Next varRow
    Application.ScreenUpdating = True
    
    Application.ScreenUpdating = True
    Worksheets("Rota Input").Calculate
    Worksheets("Rota").Calculate
    
    MsgBox "Saved.", vbInformation
    
    End Sub

    rotaexample.xlsx

  19. #19
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 'Compile Error - Procedure Too Large'

    Next step is to download SmartIndenter from http://www.oaltd.co.uk/Indenter/, install it, and indent your code.

    Then look at the resulting block structure and the problem should be apparent.

  20. #20
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: 'Compile Error - Procedure Too Large'

    Start reformatting your code so it's better to read

    Sub tst()
      With Sheets("Rota Input")
        For j = 1 To 30
          For Each dt In Array("Fri", "Sat", "Sun", "Mon", "Tues", "Wed", "Thurs","Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday")
            If TeamMbr1.Value <> "Team Mbr" And .Controls(dt & "Start" & j).Value <> "Start" And Controls(dt & "Finish" & j).Value <> "Finish" Then
              For jj = 2 To .Range("A50000").End(xlUp).Row
                If .Cells(jj, 2).Value & .Cells(jj, 4).Value & .Cells(jj, 5).Value =WeekDD2.Value & DeptDD2.Value & SiteDD2.Value and .Cells(jj, 1).Value=WeekDD2.Value & sDay & SiteDD2.Value & DeptDD2.Value & j then .Cells(jj, 12).resize(,3).Value =split(Controls(TeamMbr & j).Value & "|" & Controls(sDay & "Start" & j).Value & "|" & Controls(sDay & "Finish" & j).Value,"|")
              Next
            End If
          Next 
        Next
      End With
    
      With Sheets("Rota")
        .Range("G2").Value = WeekDD2.Value
        .Range("C2").Value = SiteDD2.Value
      End With
    End Sub
    Last edited by snb; 11-10-2010 at 06:37 PM.



  21. #21
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    It looked like I had my end if's in the wrong place so I changed it to

                                        End Select
                                        
                                    End If
    
                                Next iCnt
    
                            End If
    
                        Next vDay
    
                    End If
    
                Next sDay
    
            End If
    
            Sheets("Rota").Range("G2").Value = Me.WeekDD2.Value
            Sheets("Rota").Range("C2").Value = Me.SiteDD2.Value

    And now I get the 'next with out for' error message. I have no idea what I am doing wrong.

    I hint would be much apreciated!

    Many thanks

    Nods

  22. #22
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    Sorry Just seen your prev post, Is that your version of my code?

    I just tried to compile it and I got a syntax error on the

    If .Cells(jj, 2).Value & .Cells(jj, 4).Value & .Cells(jj, 5).Value =WeekDD2.Value & DeptDD2.Value & SiteDD2.Value and .Cells(jj, 1).Value=WeekDD2.Value & sDay & SiteDD2.Value & DeptDD2.Value & j then .Cells(jj, 12).resize(,3).Value =split(Controls(TeamMbr & j).Value & "|" & Controls(sDay & "Start" & j).Value & "|" & Controls(sDay & "Finish" & j).Value,"|")
    line

    I have used the indent add in you sugested and my code looks like this now.

    But I still cant spot the error. I'm really sorry for being a pain but i am trying to learn VBA.

    Many thanks.

    Nods

  23. #23
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    Ok So I reformated my code so it easier to read and have being trying several things but still can work out why I am getting the error. I am getting the 'invalid next control' error. Can someone please give some guidance on where I am going wrong?

    Many thanks yet again.

    nods


    Private Sub RotaAmendButton_Click()
    
        If Me.SiteDD2.Value = "Select Site" Or Me.SiteDD2.Value = "" Then
            MsgBox "Please Select a Site, Week and Department for the week you want view. If you make any changes click on 'Amend Historical Rota'. To copy the Rota to a new week, change the week and click on 'Save'.", vbInformation
            Me.SiteDD2.SetFocus
            Exit Sub
        End If
    
        If Me.WeekDD2.Value = "Select Week" Or Me.WeekDD2.Value = "" Then
            MsgBox "Please Select a Site, Week and Department for the week you want view. If you make any changes click on 'Amend Historical Rota'. To copy the Rota to a new week, change the week and click on 'Save'.", vbInformation
            Me.WeekDD2.SetFocus
            Exit Sub
    
        End If
        If Me.DeptDD2.Value = "Team/Dept" Or Me.WeekDD2.Value = "" Then
            MsgBox "Please Select a Site, Week and Department for the week you want view. If you make any changes click on 'Amend Historical Rota'. To copy the Rota to a new week, change the week and click on 'Save'.", vbInformation
            Me.DeptDD2.SetFocus
            Exit Sub
    
        End If
    
        Dim varSite As String
        Dim varWeek As String
        Dim varTeam As String
        Dim varWS As Worksheet
        Dim varLastRow As Long
        Dim varRow As Long
        Dim vDay As Variant
        Dim sDay As Variant
        Dim iCnt As Long
    
    
        Application.ScreenUpdating = False
    
        varSite = Me.SiteDD2.Value
        varWeek = Me.WeekDD2.Value
        varTeam = Me.DeptDD2.Value
    
        Set varWS = Sheets("Rota Input")
        varLastRow = varWS.Range("A50000").End(xlUp).Row
    
        For iCnt = 1 To 30
    
            For Each sDay In Array("Fri", "Sat", "Sun", "Mon", "Tues", "Wed", "Thurs")
    
                For Each vDay In Array("Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday")
    
                    If TeamMbr1.Value <> "Team Mbr" And _
                       Me.Controls(sDay & "Start" & iCnt).Value <> "Start" And _
                       Me.Controls(sDay & "Finish" & iCnt).Value <> "Finish" Then
    
                        For varRow = 2 To varLastRow
    
                            If varWS.Cells(varRow, 2).Value = varWeek Then
                                If varWS.Cells(varRow, 4).Value = varSite Then
                                    If varWS.Cells(varRow, 5).Value = varTeam Then
                                        Select Case varWS.Cells(varRow, 1).Value
    
                                        Case Me.WeekDD2.Value + sDay + Me.SiteDD2.Value + Me.DeptDD2.Value + iCnt
    
                                            varWS.Cells(varRow, 12).Value = Me.Controls(TeamMbr & iCnt).Value
                                            varWS.Cells(varRow, 13).Value = Me.Controls(sDay & "Start" & iCnt).Value
                                            varWS.Cells(varRow, 14).Value = Me.Controls(sDay & "Finish" & iCnt).Value
    
    
    
                                        End Select
                                    End If
                                End If
                            End If
    
    
                        Next iCnt
                    Next vDay
                Next sDay
    
            End If
    
            Sheets("Rota").Range("G2").Value = Me.WeekDD2.Value
            Sheets("Rota").Range("C2").Value = Me.SiteDD2.Value
    
        End If
    
    Next varRow
    Application.ScreenUpdating = True
    
    Application.ScreenUpdating = True
    Worksheets("Rota Input").Calculate
    Worksheets("Rota").Calculate
    
    MsgBox "Saved.", vbInformation
    
    End Sub
    
    Sheets("Rota").Range("G2").Value = WeekDD2.Value
    Sheets("Rota").Range("C2").Value = SiteDD2.Value
    End Sub
    
    Worksheets("Rota Input").Calculate
    Worksheets("Rota Tables").Calculate
    Worksheets("Rota").Calculate
    Worksheets("Rota").Select
    MsgBox "Saved.", vbInformation
    
    End Sub

  24. #24
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 'Compile Error - Procedure Too Large'

    Fix your control names so they consistently use 3-letter weekday abbreviations, and eliminate the needless complexity of nested loops. Look at the previous code I provided.

  25. #25
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: 'Compile Error - Procedure Too Large'

    Thanks for all of your help. I have debugged the code an it compiles. However I still cant get it to populate the form.

    I have reposted under different heading because problem is now different.

+ 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