+ Reply to Thread
Results 1 to 9 of 9

VBA Macro display 3 columns with all possible combinations of numbers between 0 and 15

  1. #1
    Registered User
    Join Date
    12-30-2019
    Location
    Norway
    MS-Off Ver
    Office 16
    Posts
    1

    VBA Macro display 3 columns with all possible combinations of numbers between 0 and 15

    Hi!

    I'm new here!
    I'm trying to create a VBA Macro to display 3 columns with all possible combinations of numbers between 0 and 15.
    Like this:

    0 0 0
    0 0 1
    0 0 2
    0 0 3
    ...
    15 15 15

    Any skilled programmers who know how to do this?
    Last edited by tnjaa; 12-30-2019 at 03:48 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: VBA Macro display 3 columns with all possible combinations of numbers between 0 and 15

    I wouldn't consider myself skilled, but how about this:

    Please Login or Register  to view this content.
    Never stop learning!
    <--- please consider *-ing !

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    The same but a bit faster :

    PHP Code: 
    Sub Demo0()
        
    Dim A%, B%, C%, R&
            
    Application.ScreenUpdating False
        
    For 0 To 15
        
    For 0 To 15
        
    For 0 To 15
            R 
    1
            Rows
    (R).Columns("A:C").Value2 = Array(ABC)
        
    Next CBA
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb

    As a beginner starter a bit more faster :

    PHP Code: 
    Sub Demo1()
      Const 
    15
        Dim D
    %(), A%, B%, C%, R&
            
    ReDim D(1 To (1) ^ 31 To 3)
        For 
    0 To U
        
    For 0 To U
        
    For 0 To U
            R 
    1
            D
    (R1) = A
            D
    (R2) = B
            D
    (R3) = C
        Next C
    BA
            
    [A1:C1].Resize(R).Value2 D
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb

    Between both previous demonstrations there are intermediate ways like for example :

    PHP Code: 
    Sub Demo01()
        
    Dim R&, CA%, B%
            
    1
            C 
    = [ROW(1:16)-1]
            
    Application.ScreenUpdating False
        
    For 0 To 15
        
    For 0 To 15
            Cells
    (R1).Resize(162).Value2 = Array(AB)
            
    Cells(R3).Resize(16).Value2 C
            R 
    16
        Next B
    A
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 12-31-2019 at 08:21 AM.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,219

    Re: VBA Macro display 3 columns with all possible combinations of numbers between 0 and 15

    No No No...Come on Marc L...No loops allowed...YOU CAN DO IT...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi sintek !

    I well know any VBA code is totally useless here just using easy formulas !
    Like tnjaa should surely achieved …
    And I'm a bit surprised you didn't post this way.

    My answer was first for harrisonland to show him first how to improve any loop procedure speed.

    So for the lazy just reproducing easy Excel formulas :

    PHP Code: 
    Sub Demo2()
        
    With [A1:C1].Resize(16 3)
            .
    Formula = [{"=INT((ROW()-1)/256)","=MOD(INT((ROW()-1)/16),16)","=MOD(ROW()-1,16)"}]
            .
    Formula = .Value2
        End With
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,219

    Re: VBA Macro display 3 columns with all possible combinations of numbers between 0 and 15

    And I'm a bit surprised you didn't post this way
    Excel Crawling, skipped I did...Straight to Running I did...lol
    I suck at formulas...Had no excel training or inclination to utilize such...

  9. #9
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: VBA Macro display 3 columns with all possible combinations of numbers between 0 and 15

    Haha, guys. Thanks for the edification

    I'm but an Excel beginner, so although I can get (some) things done, I'm grateful for learning to do things more elegantly, or efficiently!

    Hope yours was a Happy New Year.
    Tim

+ 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. Replies: 3
    Last Post: 06-13-2018, 10:30 AM
  2. Replies: 0
    Last Post: 02-02-2013, 04:20 AM
  3. Replies: 3
    Last Post: 01-22-2013, 07:11 PM
  4. How to create formula to display different combinations of numbers
    By itsme74 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-01-2012, 03:32 AM
  5. Macro to scan through groups of combinations for numbers not in the group
    By flexalong in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2009, 11:44 PM
  6. Display all combinations from a set of numbers
    By tx12345 in forum Excel General
    Replies: 7
    Last Post: 07-14-2005, 08:05 PM
  7. [SOLVED] Macro to add numbers to create combinations that equal certain amo
    By Lauren qt314 in forum Excel General
    Replies: 3
    Last Post: 04-21-2005, 01:06 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