+ Reply to Thread
Results 1 to 4 of 4

VBA to write permuatations for a given input

  1. #1
    Registered User
    Join Date
    12-12-2013
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    VBA to write permuatations for a given input

    Hi,

    I was wondering if anyone can help me write permutations in VBA.

    Suppose my inputs are A, B, C

    I would like it to yield the following results each in a separate cell

    ABC
    ACB
    BCA
    BAC
    CBA
    CAB

    I have used 3 For... Next loops however, this will not stretch if I have an input for A,B,C, D

    Any suggestions / directions most welcome. I have attached what I have currently started.

    Permutations.xlsm

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA to write permuatations for a given input

    Hi,

    Here's one way with your inputs in a contiguous range on row 1 starting in A1.
    Row 2 should be blank, results listed down column A starting at A3

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    12-12-2013
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: VBA to write permuatations for a given input

    Hi,

    It seems to be going in the right direction but it repeats itself like the below which isn't what I want.
    abc
    bca
    cab
    abc
    bca
    cab

    How can the code be amended so that it does all the perms ?

    Bilal

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA to write permuatations for a given input

    Hi,

    Substitute this code instead
    Please Login or Register  to view this content.

+ 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. Function to Input sets of data, then write the output
    By Nater5000 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-13-2013, 04:25 PM
  2. [SOLVED] ?How to Write New Input (from userform) to top (row1) each time?
    By ReedDOT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2013, 09:15 AM
  3. input items and write into a sheet then select some datas
    By m.a.asharaf ali in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-07-2012, 08:29 AM
  4. [SOLVED] write a macro to input data
    By JPreeshl in forum Excel General
    Replies: 2
    Last Post: 05-06-2006, 04:30 PM
  5. write macro to input data
    By Macro Help in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 12-29-2005, 08:10 PM

Tags for this Thread

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