Results 1 to 4 of 4

Combinations without repetition - VBA code partially working

Threaded View

  1. #1
    Registered User
    Join Date
    08-24-2014
    Location
    Romania
    MS-Off Ver
    2013
    Posts
    18

    Combinations without repetition - VBA code partially working

    Hello,

    I am having an issue with creating a macro to find all the combinations possible without repetition.
    I have attached a sample of what my worksheet looks like and the macro that I managed to do but doesn't work correctly.

    Sub ToAndFrom()
    
    Dim lastRow As Long
    Dim i As Long
    Dim j As Long
    Dim n As Long
    
    
    
    'Application.ScreenUpdating = False
    'Application.EnableEvents = False
    'Application.Calculation = xlCalculationManual
    
    lastRow = ActiveSheet.Range("N" & Rows.Count).End(xlUp).Row
    
    For n = 7 To lastRow
        For i = n To lastRow
            For j = i + 1 To lastRow
            
            Cells(i, "B").Value = Cells(n, "N").Value
            Cells(i, "C").Value = Cells(j, "N").Value
            i = i + 1
            
            Next j
        Next i
    Next n
    
    End Sub

    What I need for the code to do is this:
    I have a row ( "N" ) that has all the city names one under another, starting from position N7 and let's say it has these name: A B C D E
    In rows B and C, I need the macro to do this:
    Row B Row C
    A B
    A C
    A D
    A E
    B C
    B D
    B E
    C D
    C E
    D E

    I need all the combinations, without a repetition ( AB and BA have the same distance between them so it's pointless to have bouth)

    The VBA code that I wrote works perfectly for the first set ( AB / AC / AD / AE) but then for the next rows, it starts to overwrite the ones before so I think I need a limiter or another row count or something similar to that but I don't know where and how to modify it


    Please help
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Code only partially working
    By Saeber4777 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-11-2014, 10:53 PM
  2. [SOLVED] PC Macro only partially working on Macs
    By sdnorton in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-20-2014, 01:38 PM
  3. Macro only partially working
    By LilSisKin in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-26-2013, 06:04 PM
  4. VLOOKUP partially working
    By ih8xc in forum Excel General
    Replies: 4
    Last Post: 05-03-2011, 08:32 PM
  5. Myrna Larson code for Combinations and Permutations not working in Excel 07-Overflow
    By PokerJoe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-23-2009, 05:58 PM

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