Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'this does not actually solve the whole problem as the problem mentions that id values
- 'may occur more than once. However, it is close enough to understand
- Sub FindBigOrders()
- 'declare variables
- Dim ws As Worksheet
- Dim cell As Range
- Dim idCell As Range
- Dim amountCell As Range
- Dim counter As Integer
- Dim id As Integer
- Dim amount As Integer
- counter = 2
- 'this is discussed in previous chapters, but also on pages 136 and 137
- 'in this case I am accessing the worksheets in the current workbook named "Results"
- Set ws = ActiveWorkbook.Worksheets("Results")
- 'review page 137 to see how to use the for each loop with a range
- For Each cell In Range("amounts")
- 'does the value meet the criteria?
- If cell.Value > 2000 Then
- 'get the values
- id = cell.Offset(0, -1).Value
- amount = cell.Value
- 'write them to the other sheet
- Set idCell = ws.Cells(counter, 1)
- idCell.Value = id
- Set amountCell = ws.Cells(counter, 2)
- amountCell.Value = amount
- 'only advance the counter if we find a match
- counter = counter + 1
- End If
- Next
Advertisement
Add Comment
Please, Sign In to add comment