View Single Post
 
Old 08-17-2021, 07:10 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can simplify your code to make it faster to implement and maintain.
For instance, I would get rid of the Carreteras module and replace the UserForm_Activate macro in the userform's module with this to streamline that part.
Code:
Private Sub UserForm_Initialize()
  Dim sVia As String, arr() As String
  sVia = "AP-15:AP-68:A-1:A-10:A-12:A-15:A-21:A-68:PA-30:PA-31:PA-32:PA-33:PA-34:N-111:" & _
          "N-113:N-121:N-121-A:N-121-B:N-121-C:N-135:N-232:N-240:N-240-A"
  arr = Split(sVia, ":")
  Me.cbovia.List = arr
End Sub
Do you have a spreadsheet or table to read the possible exit values? That would make loading the dependent exits a lot more streamlined.

If you are going to enter all that data directly in VBA code, try to do it with as little duplication or complexity as possible. Graham's code could also be trimmed a bit along these lines
Code:
Private Sub CommandButton2_Click()
  Dim sVia As String, lPK As String, sTermPart As String, arr() As String
  sVia = ComboVia.Text
  lPK = textPK.Value
  Select Case sVia
    Case Is = "A-68"
      If lPK < 85 Then
        sTermPart = "Castejon|Tudela"
      ElseIf lPK < 99 Then
        sTermPart = "Corella|Estella"
      Else
        sTermPart = "Fontellas|Tafalla"
      End If
    Case Is = "NA-3010"
      If lPK < 25 Then
        sTermPart = "Cortes|Tudela"
      ElseIf lPK < 35 Then
        sTermPart = "Ribaforada|Tafalla"
      Else
        sTermPart = "Novillas|Estella"
      End If
  End Select
  If UBound(arr) > 0 Then
    arr = Split(sTermPart, "|")
    Rellenar "termino", arr(0)
    Rellenar "partido", arr(1)
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote