Exclude from array

dslaw1

New Member
Joined
Sep 20, 2011
Messages
1
HI

Basically, I have a 20 x 20 array which contains the distances between 20 cities. I need to find the closest city beginning at the starting city.

Whilst I've a programmed the minimum, I am not sure how to exclude cities that have already been visited as you cannot use these again.

My code so far is as follows:
StartCity = Me.ComboBox1.Value

SolutionArray(1) = City(StartCity)
SolutionArray(21) = City(StartCity)

MinDist = 1000
i = 2

For i = 2 To 20
For j = 1 To 20
If DistArrayTwo(StartCity, j) < MinDist And j <> StartCity Then
MinDist = DistArrayTwo(StartCity, j)
SolutionArray(i) = City(j)
End If
Next j
StartCity = SolutionArray(i)
MinDist = 1000
Next i

PLEASE HELP!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top