hey all, i have traveling salesman problem. with the below code i get the routes that i need.
but i need to add distance between cities so that i dont need to type each distance to Excel
What code do i need to add distaces?
CODE
Sub test()
x = 1
For x1 = 1 To 6
For x2 = 1 To 6
For x3 = 1 To 6
For x4 = 1 To 6
For x5 = 1 To 6
For x6 = 1 To 6
Range("k1").Value = x1
Range("k2").Value = x2
Range("k3").Value = x3
Range("k4").Value = x4
Range("k5").Value = x5
Range("k6").Value = x6
b = WorksheetFunction.CountIf(Range("k1:k6"), Range("k1"))
c = WorksheetFunction.CountIf(Range("k1:k6"), Range("k2"))
d = WorksheetFunction.CountIf(Range("k1:k6"), Range("k3"))
e = WorksheetFunction.CountIf(Range("k1:k6"), Range("k4"))
f = WorksheetFunction.CountIf(Range("k1:k6"), Range("k5"))
g = WorksheetFunction.CountIf(Range("k1:k6"), Range("k6"))
total = b + c + d + e + f + g
If total = 6 Then
Cells(x, 1).Value = "A"
Cells(x, 2).Value = Range("l1").Value
Cells(x, 3).Value = Range("l2").Value
Cells(x, 4).Value = Range("l3").Value
Cells(x, 5).Value = Range("l4").Value
Cells(x, 6).Value = Range("l5").Value
Cells(x, 7).Value = Range("l6").Value
Cells(x, 8).Value = "A"
x = x + 1
End If
Next x6
Next x5
Next x4
Next x3
Next x2
Next x1
End Sub
*Always use code blocks
This post has been edited by PsychoCoder: 2 Oct, 2007 - 06:48 PM