+ Reply to Thread
Results 1 to 11 of 11

Using a variable to set the end of a for loop

  1. #1
    Forum Contributor
    Join Date
    10-20-2008
    Location
    Gloucestershire
    Posts
    134

    Question Using a variable to set the end of a for loop

    Is it possible to use a variable to set the end of my for loop.

    I only want the loop to continue while each row in worksheet 3 contains data

    I have tried this as shown by creating a "TotalRows" Variable as shown in the code but i cant get it working.

    Please Login or Register  to view this content.
    Does anyone know how i can calculate the formulas so long as the current row the loop is on has data in it.


    Thanx George
    Last edited by gwithey; 12-18-2008 at 09:58 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
    Is there any other data on the sheet because your TotalRows variable should work. You could try
    Please Login or Register  to view this content.
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    10-20-2008
    Location
    Gloucestershire
    Posts
    134
    Thank you the code now works well and carries out the calculations.

    It is considerably slower than my other macros. Although the others only copy this data rather than calculate it.

    Is there any simple way to speed up operation other than the ways i have tried?


    Please Login or Register  to view this content.
    Thanx George

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The calculations shouldn't affect speed, Calculation is switched off whilst the macro is running. I haven't tested this but try it on a backup workbook
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    10-20-2008
    Location
    Gloucestershire
    Posts
    134
    That is a good idea for cutting it down but it doesnt work.

    Dont know if it is because there is no way of the formulas looping. It doesnt even cayy out one loop so im not sure

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Can you attach an example workbook?

  7. #7
    Forum Contributor
    Join Date
    10-20-2008
    Location
    Gloucestershire
    Posts
    134
    I noticed another thing i cannot assign this macro to the red button to calculate it.

    It only works by selecting run macro from tool bar or running straight from the editor
    Attached Files Attached Files

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The amended code seems to work fine.

    I have also set it to start the formulas in Row2
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    10-20-2008
    Location
    Gloucestershire
    Posts
    134
    That is better works well

    Do you know why i cannot execute the macro by assigning it to the red button?

    It will run but only execute 34 rows down not to the bottom of the data

    Thanx George

  10. #10
    Forum Contributor
    Join Date
    10-20-2008
    Location
    Gloucestershire
    Posts
    134
    Dont worry figured out the problem the macro would only run on the sheet when i was on that sheet so i had to reference it at the start of the macro in order to asign it to a button

    Thanx again for the help Roy

    George

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The button worked on the example that I uploaded, I had added the With Sheet.... statement.

+ 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