+ Reply to Thread
Results 1 to 11 of 11

Trips selector

Hybrid View

  1. #1
    Registered User
    Join Date
    09-04-2017
    Location
    Prague
    MS-Off Ver
    2016
    Posts
    47

    Trips selector

    Hello everybody,

    I am looking for a formula which is able to select number of trips with highest priorities.

    1 T P F
    2 M J K
    3 K Q R
    4 D G H
    5 T G H
    6 A Q R
    7 M Q R
    8 E Q R
    9 L Q R
    10 R E Q
    11 L A K
    12 B H C
    13 N M H
    14 O E Q
    15 H E Q

    This table describes that the first trip #1 goes from point "T" to point "P" to point "F". The second trip #2 goes from point "M" to point "J" to point "K". Etc.

    The result should be looking like shown below:
    1 T P F
    2 M J K
    4 D G H
    6 A Q R

    The trip number 3 is not possible to choose as a proper trip because the point "K" is already chosen in the higher priority trip #2.

    Is it possible to somehow automate those results above?

    Thank you.

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Trips selector

    =--(SUM(COUNTIF($B$1:D1,B2:D2))=0) as array formula
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    09-04-2017
    Location
    Prague
    MS-Off Ver
    2016
    Posts
    47

    Re: Trips selector

    Thank you for your reply.

    But, trip #6 is supposed to be also the right solution! Your excel file does have this solution included.

    6 A Q R

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,850

    Re: Trips selector

    ...bu Q and R are already chosen ????

  5. #5
    Registered User
    Join Date
    09-04-2017
    Location
    Prague
    MS-Off Ver
    2016
    Posts
    47

    Re: Trips selector

    I am sorry, let me clarify the situation.

    The point K is taken within the trip #2, it means that formula should skip trip #3 and not consider point Q and R as chosen. It is needed to consider all three point within each trip number.

    Thanks

  6. #6
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Trips selector

    in this case UDF
    Function vvv(d As Range, n As Long) As Long
    Dim i&, j&, jj&, mm&, ii&
    Dim dm(), ir() As Long
    ReDim dm(1 To d.Rows.Count, 1 To d.Columns.Count)
    ReDim ir(1 To d.Rows.Count)
    ir(1) = 1
    
    If n = 1 Then vvv = 1: Exit Function
    dm = d
    vvv = ir(1)
    
        For ii = 2 To n
            For i = 1 To ii - 1
    
                For j = 1 To UBound(dm, 2)
                    For jj = 1 To UBound(dm, 2)
                    mm = mm - CInt(dm(i, j) = dm(ii, jj) And ir(i) = 1)
                Next jj, j
            Next i
            If mm = 0 Then ir(ii) = 1
            vvv = ir(ii)
            mm = 0
    Next ii
    
    End Function
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    09-04-2017
    Location
    Prague
    MS-Off Ver
    2016
    Posts
    47

    Re: Trips selector

    Thank you, it works perfectly!

  8. #8
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Trips selector

    the same udf as array formula
    more effitient for large data volumes
    Function vvv(d As Range) As Long()
    Dim i&, j&, jj&, mm&, ii&, n&
    Dim dm(), ir() As Long, fff()
    n = d.Rows.Count
    ReDim dm(1 To d.Rows.Count, 1 To d.Columns.Count)
    ReDim ir(1 To d.Rows.Count, 1 To 1)
    ir(1, 1) = 1
    
    dm = d
    'vvv = ir(1)
    
        For ii = 2 To n
            For i = 1 To ii - 1
    
                For j = 1 To UBound(dm, 2)
                    For jj = 1 To UBound(dm, 2)
                    mm = mm - CInt(dm(i, j) = dm(ii, jj) And ir(i, 1) = 1)
                Next jj, j
            Next i
            If mm = 0 Then ir(ii, 1) = 1
            mm = 0
    Next ii
    vvv = ir
    End Function
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    09-04-2017
    Location
    Prague
    MS-Off Ver
    2016
    Posts
    47

    Re: Trips selector

    Quote Originally Posted by tim201110 View Post
    the same udf as array formula
    more effitient for large data volumes
    Function vvv(d As Range) As Long()
    Dim i&, j&, jj&, mm&, ii&, n&
    Dim dm(), ir() As Long, fff()
    n = d.Rows.Count
    ReDim dm(1 To d.Rows.Count, 1 To d.Columns.Count)
    ReDim ir(1 To d.Rows.Count, 1 To 1)
    ir(1, 1) = 1
    
    dm = d
    'vvv = ir(1)
    
        For ii = 2 To n
            For i = 1 To ii - 1
    
                For j = 1 To UBound(dm, 2)
                    For jj = 1 To UBound(dm, 2)
                    mm = mm - CInt(dm(i, j) = dm(ii, jj) And ir(i, 1) = 1)
                Next jj, j
            Next i
            If mm = 0 Then ir(ii, 1) = 1
            mm = 0
    Next ii
    vvv = ir
    End Function
    Thanks.

    Do you know if it is possible to created a faster code. If I have around 600 rows it takes forever. Thank you.
    Attached Files Attached Files
    Last edited by 4petris; 12-21-2017 at 04:31 AM.

  10. #10
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Trips selector

    It is strange
    "your" files are slow
    my are Dodge Vipers
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    09-04-2017
    Location
    Prague
    MS-Off Ver
    2016
    Posts
    47

    Re: Trips selector

    Thank you. Do you know what could be a reason?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Last 5 trips weight
    By lokpal.panwar in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-11-2015, 02:08 AM
  2. Counting Vehicle Trips in Date Ranges
    By johnexcel1987 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-04-2014, 12:41 PM
  3. Replies: 2
    Last Post: 07-16-2014, 12:37 PM
  4. [SOLVED] Count number of trips by occurences
    By Ucpaul in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-05-2013, 05:49 PM
  5. Formula for ordering trips from days
    By pezalmendra in forum Excel General
    Replies: 0
    Last Post: 07-27-2012, 04:26 PM
  6. selector
    By kwcarson in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-12-2005, 09:06 PM
  7. very high cpu/ram usage: many Excel/SQL Server ADO return-trips
    By Loane Sharp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2005, 04:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1