+ Reply to Thread
Results 1 to 12 of 12

Looping question

  1. #1
    Registered User
    Join Date
    06-18-2009
    Location
    Barcelona, Spain
    MS-Off Ver
    Excel 2003
    Posts
    18

    Looping question

    Only just discovered the concept of looping, was wondering if someone could help me with it. I have a simple macro for calculating values in two cells and it works. What I would like to do is repeat it for about 100 rows.

    Please Login or Register  to view this content.
    Thanks in advance for any help.
    Last edited by shak1; 07-02-2009 at 09:54 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Looping question

    There are other methods to looping available but for demo of concept:

    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Looping question

    Note that loops aren't always the most efficient way of doing things. This loop works for rows 1 to 100. You could look into the Cells rather than Range notation as it is slightly more intuitive, at least for people like me who never stop having to think which is the row and which is the column.
    Please Login or Register  to view this content.
    EDIT: DonkeyOte is ahead of me and read my mind.

  4. #4
    Registered User
    Join Date
    06-18-2009
    Location
    Barcelona, Spain
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Looping question

    Thanks for both those guys, they look like what I need, but for some reason I am getting an "Overflow" error on both codes? When i debug it says it is this line that is causing the problem

    Please Login or Register  to view this content.
    shak

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Looping question

    Perhaps a value in column I is zero or blank?

  6. #6
    Registered User
    Join Date
    06-18-2009
    Location
    Barcelona, Spain
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Looping question

    Yeah I just realized that, I have blank rows in between some of the data I want to calculate so it is trying to divide by 0 on these rows. Is there anything I can add to the code so that it skips rows that are blank?

    Shak

  7. #7
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Looping question

    You could extend your initial If statement. If possible, best to avoid blank rows in your data.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-18-2009
    Location
    Barcelona, Spain
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Looping question

    No it doesn't work because I am using the "If" part to tell it which equation to use based on which cell is blank. Thanks for the help though, i'm closer than before.

  9. #9
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Looping question

    But both cases divide by column I which is causing the problem so it wouldn't work anyway?

  10. #10
    Registered User
    Join Date
    06-18-2009
    Location
    Barcelona, Spain
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Looping question

    No the first one is multiplied by I. The way the code works is that if the F cell is blank, it will use the first formula to calculate E, and if the E cell is blank, it will use a different formula to calculate F.

    Is there a way I could maybe combine two IF functions, so that it would look something like this:

    Please Login or Register  to view this content.

  11. #11
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Looping question

    Sorry, should really put my eyes in. What about this?
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    06-18-2009
    Location
    Barcelona, Spain
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Looping question

    It works!! Thank you Stephen R...appreciate it.

+ 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