Hey,

I'm looking for a bit of assistance with writing some code that will sort customer orders by their numerical customer ID, then sum up the total of every customers order to see if it exceeds a user inputed value. If it does, it outputs the Customer ID and total order value to a new worksheet in the same book. At the end of the sub it has to undo the sort, as it was originally (on the first worksheet)

Here is what I have so far:

Dim ordertotal As Integer
Dim total As Integer
Dim i As Integer
Dim wsdata As Range
Dim customer As Range
Do
orderValue = InputBox("Please enter order sum", "Order Total", "Enter positive integer")
If IsNumeric(orderValue) Then
orderValue = CInt(orderValue)
Else
MsgBox "That is not a valid entry, Please try again"
End If
Loop Until IsNumeric(orderValue)
' Checks to see if user inputs a number, if they enter any other character they get an error message
' if they do enter an integer, we convert it from string to integer
Sheets.Add.Name = "Output"
wsdata = ActiveWorkbook.Worksheets("Data").Range("A4:C543")
wsdata.Select
ActiveWorkbook.Worksheets("Data").sort.SortFields.Clear
ActiveWorkbook.Worksheets("Data").sort.SortFields.Add Key:=Range("B4:B543"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Data").sort
.SetRange Range("A3:C543")
.Header = xlYes
.SortMethod = xlPinYin
.Apply
' Sorts the data to group all customer orders together
End With

total = 0
i = 0
With wsdata
For Each customer In Range("B4:C543")
If customer.Offset(i + 1, 0).Value = customer.Offset(i, 0) Then
total = customer.Offset(i + 1, 1).Value + customer.Offset(i, 1).Value
i = i + 1
Else
total = total + customer.Offset("i,1")
If total > orderValue Then......


________________________

I appreciate any help!

Thanks