+ Reply to Thread
Results 1 to 9 of 9

Help With Looping Macro

  1. #1
    Registered User
    Join Date
    05-16-2017
    Location
    New Jersey
    MS-Off Ver
    2010
    Posts
    51

    Exclamation Help With Looping Macro

    I am trying to make the below code as a loop since I am trying to do the same code with little change. Only thing changing is the cell range and the column change for the formula portion within the Macro. I can't continue the Macro since it's saying it's to long. Doing a call procedure wouldn't work since the Macro is already very small.


    Please Login or Register  to view this content.

    Also the bottom portion where it said (( 'Clear Contents If changed)) section I also want to create another loop if the referenced cell is change to delete the formula from the columns created from the top portion of the Macro.

    Please Login or Register  to view this content.
    I've attached my worksheet example so you may be able to see my example my Macro is working perfectly fine, but as mentioned I can't make it longer due to my procedure too large.
    Attached Files Attached Files
    Last edited by lsantana; 05-15-2019 at 08:57 AM. Reason: Add Additional Information new

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Help With Looping Macro

    Hi,

    I'll take a more detailed look later - may be a couple of days.
    However in essence you need to identify the common sections of your code and create a single procedure.

    In the new code use variables to identify things like different ranges. You can pass variables to a procedure with a Call instruction,


    Please Login or Register  to view this content.


    Please Login or Register  to view this content.

    The other method is to declare Public Variables and in the Control procedure assign the value to the variable before calling the MainCode. In that case you don't need to specify the values you are passing within the parentheses (), in the Control procedure or the main procedure
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-16-2017
    Location
    New Jersey
    MS-Off Ver
    2010
    Posts
    51

    Re: Help With Looping Macro

    The Macro is so small using the call procedure probably won't do much. Possibly only solution I could think of is with a loop which changes the intersect target and runs the macro while changing the range and formula column. I highlighted in red the changing ranges.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-16-2017
    Location
    New Jersey
    MS-Off Ver
    2010
    Posts
    51

    Re: Help With Looping Macro

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    I'll take a more detailed look later - may be a couple of days.
    However in essence you need to identify the common sections of your code and create a single procedure.

    In the new code use variables to identify things like different ranges. You can pass variables to a procedure with a Call instruction,


    Please Login or Register  to view this content.


    Please Login or Register  to view this content.

    The other method is to declare Public Variables and in the Control procedure assign the value to the variable before calling the MainCode. In that case you don't need to specify the values you are passing within the parentheses (), in the Control procedure or the main procedure
    Hello Richard Buttrey sorry to bother, but did you have any luck trying to find a shirked version of my Macro?

  5. #5
    Valued Forum Contributor
    Join Date
    12-14-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    439

    Re: Help With Looping Macro

    Maybe it look like this
    Please Login or Register  to view this content.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Help With Looping Macro

    Quote Originally Posted by huuthang_bd View Post
    Maybe it look like this
    The question is does it work? If so great.

    There are often different ways of getting to the same goal.
    One approach I was suggesting was to identify blocks of code that are essentially the same structure and use one block of code to which you pass variables like sheet names, ranges etc.

    Incidentally it's much better practice to use VBA sheet code names rather than sheet tab names.
    e.g. instead of Worksheets("Sheet3").Range... use instead Sheet3.Range
    Tab names are to easily changed and code that uses them will then fail.

  7. #7
    Valued Forum Contributor
    Join Date
    12-14-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    439

    Re: Help With Looping Macro

    I just edit original code. However, in some case, you don't know how is bester because maybe someone will ask why two file has same structure (has same sheet (tab) name but different codename because user don't know what is codename) but the macro correct with one and incorrect with one.

  8. #8
    Registered User
    Join Date
    05-16-2017
    Location
    New Jersey
    MS-Off Ver
    2010
    Posts
    51

    Re: Help With Looping Macro

    Quote Originally Posted by huuthang_bd View Post
    Maybe it look like this
    Please Login or Register  to view this content.
    Thank you so much huuthang_bd the code work perfect with just simple errors from my request. I tweaked your code a tiny bit to make it do exactly what I needed and it's running perfectly now thanks to your code. I've posted my tweaked version below in case someone else on this form might find it helpful, thank you again so much I greatly appreciate it.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-16-2017
    Location
    New Jersey
    MS-Off Ver
    2010
    Posts
    51

    Re: Help With Looping Macro

    Quote Originally Posted by Richard Buttrey View Post
    The question is does it work? If so great.

    There are often different ways of getting to the same goal.
    One approach I was suggesting was to identify blocks of code that are essentially the same structure and use one block of code to which you pass variables like sheet names, ranges etc.

    Incidentally it's much better practice to use VBA sheet code names rather than sheet tab names.
    e.g. instead of Worksheets("Sheet3").Range... use instead Sheet3.Range
    Tab names are to easily changed and code that uses them will then fail.
    Thank you Richard Buttrey as well.

+ 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. [SOLVED] Macro to create a looping macro to populate another worksheet.
    By sungen99 in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 06-22-2016, 10:53 AM
  2. Help with looping my macro
    By dry in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2015, 11:19 AM
  3. Macro (Looping)
    By daviieejay in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2013, 05:05 PM
  4. VBA Looping Macro Help Please!
    By harrison298 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2012, 01:24 PM
  5. Looping a macro
    By cmb80 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2010, 07:52 AM
  6. Looping macro
    By DaSuPeR in forum Excel Programming / VBA / Macros
    Replies: 44
    Last Post: 06-02-2008, 01:25 PM
  7. Need help with my looping macro
    By Pete in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2005, 08:06 PM

Tags for this Thread

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