HI, I got a problem on the invoking of macro. What I have done is just design a function which is shown in the following:
-----------------------------------------------------------
Function update()
Dim I As Integer
Dim Lorry_number As Integer
Dim J As Integer
Dim K As Integer
Dim TRIPS(1 To 100) As Integer
Dim Same As Boolean
Dim Count As Integer
Dim Column As Integer
Dim Row As Integer
Dim M As Integer
Dim N As Integer
Dim Temp As Double
'Initialise the array TRIPS(K) and give the value 0 to each element
For K = 1 To 100
TRIPS(K) = 0
Next K
'Fill in "Validate the model" table
For I = 1 To 197
Lorry_number = Cells(I + 10, 19)
Same = False
'In the second time, the same lorry is found in the records,
'scan the relevant row in "Validate the model" according to the lorry number,avoid the same dispatch time record
If TRIPS(Lorry_number) > 0 Then
For K = 1 To TRIPS(Lorry_number)
If Cells(I + 10, 27) = Cells(Lorry_number + 10, 93 + 2 * (K - 1)) Then
Same = True
If Same Then
Exit For
End If
End If
Next K
End If
'if the record found is different from those in the relevant row in "Validate the model" table,
'fill in the dispatch time and the arrival time in the relevant cells
If Not Same Then
'If Cells(I + 10, 26) <> Cells(Lorry_number + 10, 93 + (2 * (TRIPS(Lorry_number) - 1))) Then
Cells(Lorry_number + 10, 93 + 2 * TRIPS(Lorry_number)) = Cells(I + 10, 27)
Cells(Lorry_number + 10, 94 + 2 * TRIPS(Lorry_number)) = Cells(I + 10, 31)
TRIPS(Lorry_number) = TRIPS(Lorry_number) + 1
'End If
End If
Next I
'Bubble sorting for the "validate the model" table, make sure each dispatch time and arrival time in ascending order
For Row = 1 To 51
Count = 0
Column = 93
'Count non-empty cells for each row
Do While Cells(Row + 10, Column) <> ""
Count = Count + 1
Column = Column + 1
Loop
'Start the sorting at least 2 pairs of dispatch time and arrival time found
If Count > 2 Then
For M = 1 To Count - 3 Step 2
For N = M + 2 To Count - 1 Step 2
If Cells(Row + 10, M + 92) > Cells(Row + 10, N + 92) Then
'Swap dispatch time cells
Temp = Cells(Row + 10, N + 92)
Cells(Row + 10, N + 92) = Cells(Row + 10, M + 92)
Cells(Row + 10, M + 92) = Temp
'Swap arrival time cells
Temp = Cells(Row + 10, N + 93)
Cells(Row + 10, N + 93) = Cells(Row + 10, M + 93)
Cells(Row + 10, M + 93) = Temp
End If
Next N
Next M
End If
Next Row
End Function
-----------------------------------------------------------
at the same time, I need to use Evolver 4.0.5 to solve the problem. I have deburged the code,but I havent found any problem in the code. However, when I put "=update()"in one of the blank cell, and click the tick let the VBA run, but it is not working properly. Can anyone give any help on this aspect?
-----------------------------------------------------------
Function update()
Dim I As Integer
Dim Lorry_number As Integer
Dim J As Integer
Dim K As Integer
Dim TRIPS(1 To 100) As Integer
Dim Same As Boolean
Dim Count As Integer
Dim Column As Integer
Dim Row As Integer
Dim M As Integer
Dim N As Integer
Dim Temp As Double
'Initialise the array TRIPS(K) and give the value 0 to each element
For K = 1 To 100
TRIPS(K) = 0
Next K
'Fill in "Validate the model" table
For I = 1 To 197
Lorry_number = Cells(I + 10, 19)
Same = False
'In the second time, the same lorry is found in the records,
'scan the relevant row in "Validate the model" according to the lorry number,avoid the same dispatch time record
If TRIPS(Lorry_number) > 0 Then
For K = 1 To TRIPS(Lorry_number)
If Cells(I + 10, 27) = Cells(Lorry_number + 10, 93 + 2 * (K - 1)) Then
Same = True
If Same Then
Exit For
End If
End If
Next K
End If
'if the record found is different from those in the relevant row in "Validate the model" table,
'fill in the dispatch time and the arrival time in the relevant cells
If Not Same Then
'If Cells(I + 10, 26) <> Cells(Lorry_number + 10, 93 + (2 * (TRIPS(Lorry_number) - 1))) Then
Cells(Lorry_number + 10, 93 + 2 * TRIPS(Lorry_number)) = Cells(I + 10, 27)
Cells(Lorry_number + 10, 94 + 2 * TRIPS(Lorry_number)) = Cells(I + 10, 31)
TRIPS(Lorry_number) = TRIPS(Lorry_number) + 1
'End If
End If
Next I
'Bubble sorting for the "validate the model" table, make sure each dispatch time and arrival time in ascending order
For Row = 1 To 51
Count = 0
Column = 93
'Count non-empty cells for each row
Do While Cells(Row + 10, Column) <> ""
Count = Count + 1
Column = Column + 1
Loop
'Start the sorting at least 2 pairs of dispatch time and arrival time found
If Count > 2 Then
For M = 1 To Count - 3 Step 2
For N = M + 2 To Count - 1 Step 2
If Cells(Row + 10, M + 92) > Cells(Row + 10, N + 92) Then
'Swap dispatch time cells
Temp = Cells(Row + 10, N + 92)
Cells(Row + 10, N + 92) = Cells(Row + 10, M + 92)
Cells(Row + 10, M + 92) = Temp
'Swap arrival time cells
Temp = Cells(Row + 10, N + 93)
Cells(Row + 10, N + 93) = Cells(Row + 10, M + 93)
Cells(Row + 10, M + 93) = Temp
End If
Next N
Next M
End If
Next Row
End Function
-----------------------------------------------------------
at the same time, I need to use Evolver 4.0.5 to solve the problem. I have deburged the code,but I havent found any problem in the code. However, when I put "=update()"in one of the blank cell, and click the tick let the VBA run, but it is not working properly. Can anyone give any help on this aspect?