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?
Bookmarks