+ Reply to Thread
Results 1 to 18 of 18

Excel Macro - Procedure Too Large

  1. #1
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30

    Excel Macro - Procedure Too Large

    I am using following event macro and it repeats itself more than 300 times. I am at a stage where I am getting a message "Compile Error, Procedure too large", I tried to break it into two but that's not working. Any ideas?


    Option Explicit
    Option Compare Text
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cl As Range
    Dim lng As Long
    Application.EnableEvents = False

    Select Case Target.Address
    Case "$E$3"
    If Target.Value = "Yes" Then
    SelectNumber:
    lng = Application.InputBox("Please enter number 0 to 100", , , , , , , 1)
    If IsNumeric(lng) = False Or lng < 0 Or lng > 100 Then GoTo SelectNumber
    Range("G3") = lng
    Else: Range("G3") = 0

    .................................................(above statements repeat more than 300 times for different cells)................................


    Application.EnableEvents = True

    End Sub
    Last edited by saeed9313; 10-15-2008 at 10:50 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    saeeed this is the second time that you have not used Code Tags, please make sure that you understand them & use them in future.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30
    I am not doing it intentionally, how you do that?

    Thanks

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try with this code... I hope it can help:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by saeed9313 View Post
    I am not doing it intentionally, how you do that?

    Thanks
    This is explained in the Forum Rules which you should have read.

    To add Code Tags select the code in your post and then click # in the toolbar above the input box.

    To edit a post you need to click the Edit button then click Go Advanced then follow the previous steps.

  6. #6
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30

    Excel Macro - Procedure Too Large (Repost)

    I am using following event macro and it repeats itself more than 300 times. I am at a stage where I am getting a message "Compile Error, Procedure too large", I tried to break it into two but that's not working. Any ideas?

    Please Login or Register  to view this content.


    .................................................(above statements repeat more than 300 times for different cells)................................


    Thanks

  7. #7
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30
    Thanks for your help. I have reposted it. You can delete this thread. I tried it to do myself but couldn't.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Threads merged and antoka05's post restored.

    There is no reason to repeat code 300 times -- you only need one block of code and some additional logic. Without knowing what you're trying to do, I can't make a more specific suggestion.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    What do you mean it repeats 300 times?

  10. #10
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30
    Please see the attachment. It has whole procedure.

    Thanks.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30
    Basically user has to answer more than 300 questions and each "select statement" represents each question. That's why I have repeated it so many times.

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Are all the answers in Column E?

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Assuming that you have all the answers entering into Column E and the results in G

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30
    No, those are under four categories.

    Category 1. Column E (Yes/No) Column G (Response)
    Category 2. Column X (Yes/No) Column Z (Response)
    Category 3. Column AQ (Yes/No) Column AS (Response)
    Category 4. Column BJ (Yes/No) Column BL (Response)

    All categories have to be in same sheet. Thanks!

  15. #15
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482
    This should make your problem more managable and the code short.

    On sheet3 is a named range which contains all the valid target addresses that need to display the Input box.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  16. #16
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30
    Plus each row doesn't have question. I tried above code it runs in every row of column E which is problametic as I do have Yes/no options for other situations in Column E to which this macro doesn't apply and that's why I wrote individual statement for each question (row).

  17. #17
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30
    Thanks Andy!

    I will give it a shot.

  18. #18
    Registered User
    Join Date
    10-07-2008
    Location
    USA
    Posts
    30

    Smile Solved

    Thanks Andy, it worked, I will customize it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. SharePoint and Excel Macro Interactivity
    By maverick_abhi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-17-2011, 04:09 PM
  2. Rename Excel File via FTP using macro
    By buczacz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-12-2007, 04:20 PM
  3. Excel Macro not executing from Oracle Forms
    By bavinash05 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2007, 03:35 AM
  4. country finder lookup macro
    By theghost in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2007, 10:41 PM
  5. Newbie... Macro - Importing multiple csv files to excel
    By dugong in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-24-2006, 05:04 AM

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