Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default MACRO FOR COMBINATIONS !!

In each cell in Range A1:M1, there is data (either a number or an
alphabet).

I need a macro to ask "How many items do you wanna combine?" When I
enter the number, the macro will list all the possible combinations of
the alphabets Or numbers I can choose from A1:M1 starting in cell A3.

Any help would be appreciated.

Thanks
Jay Dean

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default MACRO FOR COMBINATIONS !!

This sounds an awful lot about a previous post by someone else a while ago
even down to the answer in A3. Anyway, here it an adjustment to the answer
to that question.

Sub Combinations()
Dim n As Integer, m As Integer
Dim v As Variant, rng As Range
numcomb = 0
Set rng = Range("A1:M1")
'Set rng = rng.Resize(1, 5)
v = Application.Transpose(Application _
.Transpose(rng))
n = UBound(v, 1)
m = InputBox("Taken how many at a time?", "Combinations")
If Application.Combin(n, m) 64530 Then
MsgBox "Too many to write out, quitting"
Exit Sub
End If
Range("A3").Select
Comb2 n, m, 1, "'", v
End Sub

'Generate combinations of integers k..n taken m at a time, recursively
Sub Comb2(ByVal n As Integer, ByVal m As Integer, _
ByVal k As Integer, ByVal s As String, v As Variant)
Dim v1 As Variant
If m n - k + 1 Then Exit Sub
If m = 0 Then
'Debug.Print "-" & s & "<-"
v1 = Split(Replace(Trim(s), "'", ""), " ")
For i = LBound(v1) To UBound(v1)
ActiveCell.Offset(0, i) = v(v1(i))
Next
ActiveCell.Offset(1, 0).Select
Exit Sub
End If
Comb2 n, m - 1, k + 1, s & k & " ", v
Comb2 n, m, k + 1, s, v
End Sub

will generate the combinations of which you speak.

--
Regards,
Tom Ogilvy


"jay dean" wrote in message
...
In each cell in Range A1:M1, there is data (either a number or an
alphabet).

I need a macro to ask "How many items do you wanna combine?" When I
enter the number, the macro will list all the possible combinations of
the alphabets Or numbers I can choose from A1:M1 starting in cell A3.

Any help would be appreciated.

Thanks
Jay Dean

*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default MACRO FOR COMBINATIONS !!

Hi Tom - Thanks! Your code works perfectly. I am the same guy from whom
the other post was (i.e) Jay Dean, unless there's yet some other post
you were talking about.

I cannot explain why the double-posting occurred because I think I
posted my message once, but hey, these things do happen...

Anyway, thanks again for the help. I hope this response does not post
twice...LOL!

Jay Dean.


*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default MACRO FOR COMBINATIONS !!

this was from a guy posting as MAXI doing something with KENO as I recall.

--
Regards,
Tom Ogilvy


"jay dean" wrote in message
...
Hi Tom - Thanks! Your code works perfectly. I am the same guy from whom
the other post was (i.e) Jay Dean, unless there's yet some other post
you were talking about.

I cannot explain why the double-posting occurred because I think I
posted my message once, but hey, these things do happen...

Anyway, thanks again for the help. I hope this response does not post
twice...LOL!

Jay Dean.


*** Sent via Developersdex http://www.developersdex.com ***



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a macro in excel so that it can generate a list ofunique records using all permutations and combinations of the data in eachrow ad column Rizwan[_4_] Excel Discussion (Misc queries) 1 August 6th 09 01:44 PM
all possible combinations. Gaurav[_4_] Excel Discussion (Misc queries) 4 March 19th 09 06:15 PM
Macro/Function for Keyboard button combinations Matt Excel Programming 1 December 22nd 05 07:31 PM
Macro to add numbers to create combinations that equal certain amo Lauren qt314 Excel Discussion (Misc queries) 3 April 21st 05 05:57 PM
All combinations Seokho Moon Excel Programming 7 October 22nd 04 10:19 PM


All times are GMT +1. The time now is 03:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"