Form number combinations of two from an InputBox entry

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I need a script that takes an InputBox entry separated by commas then form number combinations of two from the data entered. The InputBox will always take a maximum of 5 numbers separated by commas. Example "00,01,02,03,04"

And then form all the combination of two :
"00-01"
"00-02"
"00-03"
"00-04"
"01-02"
"01-03" etc

I want to get the output displayed with a message box or any cool way is okay maybe display it in a listbox or whatever.

I want someone here figure out how to do it for me.
Regards
Kelly
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this for results in column "B"
Code:
[COLOR=navy]Sub[/COLOR] MG16Aug06
[COLOR=navy]Dim[/COLOR] nstr [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] nn [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Sp [COLOR=navy]As[/COLOR] Variant, c [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Dim[/COLOR] Message [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] Title [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] Default [COLOR=navy]As[/COLOR] [COLOR=navy]String[/COLOR]
Message = "Enter Numbers seperated by commas"    
Title = "Combinations x 2"
Default = "00,01,02,03,04"
nstr = InputBox(Message, Title, Default)
 
Sp = Split(nstr, ",")
[COLOR=navy]For[/COLOR] n = 0 To UBound(Sp)
    [COLOR=navy]For[/COLOR] nn = n + 1 To UBound(Sp)
        c = c + 1
        Cells(c, 2) = Sp(n) & "," & Sp(nn)
    [COLOR=navy]Next[/COLOR] nn
 [COLOR=navy]Next[/COLOR] n
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Try this for results in column "B"
Code:
[COLOR=navy]Sub[/COLOR] MG16Aug06
[COLOR=navy]Dim[/COLOR] nstr [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] nn [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Sp [COLOR=navy]As[/COLOR] Variant, c [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Dim[/COLOR] Message [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] Title [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] Default [COLOR=navy]As[/COLOR] [COLOR=navy]String[/COLOR]
Message = "Enter Numbers seperated by commas"    
Title = "Combinations x 2"
Default = "00,01,02,03,04"
nstr = InputBox(Message, Title, Default)
 
Sp = Split(nstr, ",")
[COLOR=navy]For[/COLOR] n = 0 To UBound(Sp)
    [COLOR=navy]For[/COLOR] nn = n + 1 To UBound(Sp)
        c = c + 1
        Cells(c, 2) = Sp(n) & "," & Sp(nn)
    [COLOR=navy]Next[/COLOR] nn
 [COLOR=navy]Next[/COLOR] n
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick

Hi
Hi @MickG,

How do I get three combinations?
 
Upvote 0
Okay have been able to fix it.

Code:
Sub[/COLOR] MG16Aug06
[COLOR=navy]Dim[/COLOR] nstr [COLOR=navy]As[/COLOR] [COLOR=navy]String,nnn as long, [/COLOR] nn [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Sp [COLOR=navy]As[/COLOR] Variant, c [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Dim[/COLOR] Message [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] Title [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] Default [COLOR=navy]As[/COLOR] [COLOR=navy]String[/COLOR]
Message = "Enter Numbers seperated by commas"    
Title = "Combinations x 2"
Default = "00,01,02,03,04"
nstr = InputBox(Message, Title, Default)
 
Sp = Split(nstr, ",")
[COLOR=navy]For[/COLOR] n = 0 To UBound(Sp)
    [COLOR=navy]For[/COLOR] nn = n + 1 To UBound(Sp)
     [COLOR=navy][FONT=Verdana]For[/FONT][/COLOR][FONT=Verdana] nnn = nn + 1 To UBound(Sp)[/FONT]



        c = c + 1
        Cells(c, 2) = Sp(n) & "," & Sp(nn) & "," & Sp(nnn)

      Next nnn 
    [COLOR=navy]Next[/COLOR] nn
 [COLOR=navy]Next[/COLOR] n
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top