+ Reply to Thread
Results 1 to 6 of 6

Triggering a loop within a loop

  1. #1
    Registered User
    Join Date
    08-13-2007
    Posts
    10

    Triggering a loop within a loop

    Hi Everyone

    The problem I have is that I have the table below:

    Q Px
    Buy 100 101
    Buy 100 102
    Buy 100 103
    Sell 300 102
    Buy 140 111

    From this I want to find out what the average price is after the buys and sells become 0. I know how to say in words what to do in VBA but am having some problems actually doing it.

    What I want to do is:

    VBA Logic:
    1. First step have I bought more or sold more? (Not a problem i can do this)
    2. Then I want to loop down until the Buy and Sell equals 0 or near enough
    3. Following this I want to start another loop AFTER the point that sells and buys become 0. This will then work out the the Average price after that

    All i really need to know is how to start another loop after a certain point has been met. I am using the below code that I have written which tells me the Net position i but need to put something in there that tells me when i have reached 0 to start the second loop and start weighting the price against the quantity. (Not easy)

    Please Login or Register  to view this content.
    Any pointers would be greatly appreciated

    Kind regards

    Robin
    Last edited by VBA Noob; 01-09-2008 at 04:49 PM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Robin,

    Please read forum rules and message to cross posters below and then add the link to the other forum

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    08-13-2007
    Posts
    10
    Hi VBA Noob

    Thanks for the link. I read the page and appreciate what has been said. I won't cross post unless it has had a couple of weeks without an answer

    All the best

    Robin

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    and then add the link to the other forum
    Cross posting is permitted. We only ask you add the link to the other forum

    VBA Noob

  5. #5
    Registered User
    Join Date
    08-13-2007
    Posts
    10
    Hi VBA Noob

    This is the link to the other posting and is the same question as is posted above

    http://www.mrexcel.com/forum/showthr...90#post1457490

    Any ideas?

    Robin

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Robin

    Maybe this will give you some ideas. Say your data as shown is in the range A1:C5 then run

    Please Login or Register  to view this content.
    HTH

    rylo

+ 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