Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,179 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,002 people online right now. Registration is fast and FREE... Join Now!




Adding distance matrix to the VB

 
Reply to this topicStart new topic

Adding distance matrix to the VB

mutu
2 Oct, 2007 - 06:44 PM
Post #1

New D.I.C Head
*

Joined: 30 Sep, 2007
Posts: 5


My Contributions
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 smile.gif

This post has been edited by PsychoCoder: 2 Oct, 2007 - 06:48 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 01:01AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month