Results 1 to 10 of 10

coding to add values until a certain limit

Threaded View

dan2010 coding to add values until a... 08-16-2010, 01:16 AM
royUK Re: coding to add values... 08-16-2010, 01:23 AM
dan2010 Re: coding to add values... 08-16-2010, 03:47 AM
dan2010 Re: coding to add values... 08-16-2010, 03:54 AM
Andrew-R Re: coding to add values... 08-16-2010, 04:40 AM
dan2010 Re: coding to add values... 08-16-2010, 04:50 AM
Andrew-R Re: coding to add values... 08-16-2010, 04:56 AM
dan2010 Re: coding to add values... 08-16-2010, 05:05 AM
Andrew-R Re: coding to add values... 08-16-2010, 05:11 AM
dan2010 Re: coding to add values... 08-16-2010, 05:18 AM
  1. #1
    Forum Contributor
    Join Date
    08-04-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    143

    coding to add values until a certain limit

    Hi,

    i would like to know what is wrong with my coding. This coding is supposed to let excel list down all the items of which the total cost is within budget and paste these items on sheet2. the budget will be declared at cell E2 by user. the result of my coding gives me only the 1st item in sheet 2 although i set the budget to be 100.


    sheet 1:
    Location " risk value " "cost "
    a 12 12
    b 10 32
    c 7 10
    d 5 15

    Dim i As Integer
    Dim sum As Long
    Dim budget As Long
    
    budget = sheet1.Range("e2").Value
    sum = 0
    
    For i =0 To i=1000000#
    If sum < budget Then
    sum = sum + sheet1.Cells(i+2,3).Value
    Sheet1.Cells(i+2,1).EntireRow.Copy
    Sheet2.Cells(i+2,1).Pastespecial
    
    i=i+1
    
    End IF
    Next i
    
    worksheets("sheet2").Activate
    
    End Sub
    what if my cost and risk values are formulas based on other factors in sheet1. what adjustments do i have to make to allow excel to copy only the name, values of cost and risk values into sheet 2?
    Last edited by dan2010; 08-16-2010 at 05:22 AM.

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