+ Reply to Thread
Results 1 to 29 of 29

Procedure Too Long

  1. #1
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Procedure Too Long

    Is there any way to make this code shorter? I need to replicate it from every new tab I add. I think I will have about 40 of them.

    Or how can I run a marco that will run the code on each sheet without it wiping out all the info it pulled on the pervious sheet?


    This is what I have now:

    Please Login or Register  to view this content.
    Last edited by romperstomper; 10-04-2010 at 04:21 PM. Reason: tags

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Procedure Too Long..Please Help!!

    Range("A3") to Range("H3") can be Cells(3,1) to Cells(3,8)

    You could do a For i = 1 to 8 : ....cells(3,i) .... : next i

    Also - I hope you have the code in a module and not behind each sheet in the workbook? right?

  3. #3
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    I have it in the module. I was just trying some different things. I'm new to marco's.

    Would this change let the code be longer?

  4. #4
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    I dont think I now how to write that. Can you write an example?

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

    Re: Procedure Too Long

    See if this does the same as that:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Procedure Too Long

    Hi Nick,

    To show you how I'd use the For Next loop, see my code below.
    Please Login or Register  to view this content.
    Everybody has their favorite methods and by reading other peoples code we all learn. Shg is a real pro and I'd never suggest my code is better. The problem is that I understand my own code and techniques and can modify it easier than understanding others.

    I need to start using shg's For Each looping as it is cool. I just grew up before this was allowed. I'm stuck with a better understanding of For ... Next.

    I hope having 2 examples of what you did helps.

  7. #7
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    Thanks MavinP and Shg. This is great.

    Shg
    So if I wanted to add this code to include worksheet "J. Bobango", would I just copy and paste everything below the first set and change the worksheet name?

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

    Re: Procedure Too Long

    It does it to all worksheets except sheet All.

  9. #9
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    When I run it, it only pulls information to "King Rogers" sheet.

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

    Re: Procedure Too Long

    When I run it, it only pulls information to "King Rogers" sheet.
    That's true. I don't know what else you want it to do.

  11. #11
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    It needs to do the same thing in everysheet at the same time without wiping out the previous sheet.

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

    Re: Procedure Too Long

    Nick, I have no idea what that means. Maybe Marvin understands.

  13. #13
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    I have more than one sheet in the workbook.
    "All" has the information I need. "King Rogers", "J Smith" , "Nick"...... is where I need the information to copy to. The information from "All" that needs to be copied depends on what numbers are in the A3:H3 cells of the other sheets. Sorry for the confusion. I tried to attach my workbook but the it will not let me for some reason. It keeps telling me to refresh the page.

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

    Re: Procedure Too Long

    Do the cells A3:H3 contain the exact names of the destination sheets?

  15. #15
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Procedure Too Long

    Marvin understands very little.
    BTW - I should have suggested pivot tables, you are sounding like me.

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Procedure Too Long

    Hi Nick

    If this relates to your previous post, try zipping your file. You've got a lot of formatting going on in your file such that it may be too large (although you should have gotten a message to that effect). Try it, it may work.

    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  17. #17
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    In the "All" sheet in Column C there are ID numbers. If one of those ID numbers is entered in A3:H3 of the other sheets I need all of the row to be copied to that sheet.

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Procedure Too Long

    Hi Nick

    Having seen your workbook in a previous thread, I've a sense of what you're trying to accomplish. I've modified your posted code very slightly so that it cycles through every worksheet in the workbook and performs the same task on each sheet. I've not attempted to make the code "shorter" but you don't need to recreate it for each sheet.

    Hope this helps.

    John
    Please Login or Register  to view this content.

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

    Re: Procedure Too Long

    Please Login or Register  to view this content.
    Last edited by snb; 10-05-2010 at 12:23 PM.



  20. #20
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    Thanks everyone

    snb- i am getting an Run time error 1004 - Autofilter method of range class frailed


    Jaslake- i havent tried yours yet.

  21. #21
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    Jaslake- That worked perfect. Thanks for your help.
    This is off this topic and my be hard for me to explain: I need a code that will make an weighted average rate? I have a list of the different customers account. Each row starting at row 5 and information about the accounts. In column B it tells what type of account they own. If it says "Note" then I want the amount in the C column to be divided by $A$1 then multiplied by the number in the D column of the same row. The products of all the different "Note"s that were calculated needs to be added together in B2.

    I'm not sure if you can understand my terrible explanation but any help is better than what I've got.

    Thanks again
    Nick

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

    Re: Procedure Too Long

    Look for the difference...

    Please Login or Register  to view this content.

  23. #23
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Procedure Too Long

    Hi Nick

    You're right, it's off topic. I'd suggest you start a new thread. If you attach a copy of what you have and what you'd like it to be, you'll be certain to get quicker response with a solution tailored to your needs.

    John

  24. #24
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Procedure Too Long

    Hi snb

    I found the difference but I had to work at it. How cryptic.

    John

  25. #25
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    Havent had any luck finding the difference. Could you tell me?

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

    Re: Procedure Too Long

    Sheets("All").usedrange.columns(3)

  27. #27
    Registered User
    Join Date
    09-21-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Procedure Too Long

    I dont know enough about this to figure it out. I probably need to take some kind of class so I can better understand these things. I never once looked at any macro's before a few ago. My boss told me about this report he wanted and this is the only way I thought it could be done. Anyways thanks for the help.

  28. #28
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Procedure Too Long

    Hi Nick

    I'll be happy to help you any way I can. Regarding this
    Please Login or Register  to view this content.
    I indeed found the difference
    Please Login or Register  to view this content.
    and got this error message when the "corrected" procedure is run against your file
    Run time error 1004 - AutoFilter method of range class failed
    I haven't tried to debug the code because it's too cryptic for my limited knowledge. Perhaps snb can debug using your sample file at http://www.excelforum.com/excel-prog...uotfilter.html

    Regarding this
    I need a code that will make an weighted average rate? I have a list of the different customers account. Each row starting at row 5 and information about the accounts. In column B it tells what type of account they own. If it says "Note" then I want the amount in the C column to be divided by $A$1 then multiplied by the number in the D column of the same row. The products of all the different "Note"s that were calculated needs to be added together in B2.
    Please start a new thread and attach a copy of what you have and what you'd like it to be. You'll be certain to get quicker response with a solution tailored to your needs.

    If you wish, PM me when you've done so. Help us, we'll help you.

    John

  29. #29
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Procedure Too Long

    Hi Nick3535

    I see you got this issue resolved
    I need a code that will make an weighted average rate? I have a list of the different customers account. Each row starting at row 5 and information about the accounts. In column B it tells what type of account they own. If it says "Note" then I want the amount in the C column to be divided by $A$1 then multiplied by the number in the D column of the same row. The products of all the different "Note"s that were calculated needs to be added together in B2.
    Good for you.

    John

+ 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