Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data series
I have a set of data, let say start from A1 to F1 = 1,2,3,4,5,6
I need to have a macro to create the output as follow: A2 to D2 = 1,2,3,4 A3 to D3 = 1,2,3,5 A4 to D4 = 1,2,3,6 A5 to D5 = 1,2,4,5 A6 to D6 = 1,2,4,6 .. .. .. An to Dn = 1,4,5,6 .. .. .. Ax to Dx = 3,4,5,6 Basically, the macro should create any four combination from the data. Thank you |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data series
Hi
Your post implies that you don't want to include combinations where the order of the original data changes e.g: 1,2,4,3 This is pretty rough but try: Sub Pop2() Dim theData(5) As Integer 'change data type to suit values in A1:F1 Dim i As Integer Dim rct As Long Dim r1 As Integer Dim r2 As Integer Dim r3 As Integer Dim r4 As Integer Application.ScreenUpdating = False For i = 0 To 5 theData(i) = Cells(1, i + 1).Value Next i rct = 2 For r1 = 0 To 2 For r2 = 1 To 3 For r3 = 2 To 4 For r4 = 3 To 5 If r1 < r2 And r2 < r3 And r3 < r4 Then Cells(rct, 1) = theData(r1) Cells(rct, 2) = theData(r2) Cells(rct, 3) = theData(r3) Cells(rct, 4) = theData(r4) rct = rct + 1 End If Next Next Next Next Application.ScreenUpdating = True End Sub If you did want to include all combinations of the data including changes to the order then: Sub Pop() Dim theData(5) As Integer 'change data type to suit values in A1:F1 Dim i As Integer Dim rct As Long Dim r1 As Integer Dim r2 As Integer Dim r3 As Integer Dim r4 As Integer Application.ScreenUpdating = False For i = 0 To 5 theData(i) = Cells(1, i + 1).Value Next i rct = 2 For r1 = 0 To 5 For r2 = 0 To 5 For r3 = 0 To 5 For r4 = 0 To 5 If r1 < r2 And r1 < r3 And r1 < r4 _ And r2 < r3 And r2 < r4 _ And r3 < r4 Then Cells(rct, 1) = theData(r1) Cells(rct, 2) = theData(r2) Cells(rct, 3) = theData(r3) Cells(rct, 4) = theData(r4) rct = rct + 1 End If Next Next Next Next Application.ScreenUpdating = True End Sub Hope this helps Rowan "broogle" wrote: I have a set of data, let say start from A1 to F1 = 1,2,3,4,5,6 I need to have a macro to create the output as follow: A2 to D2 = 1,2,3,4 A3 to D3 = 1,2,3,5 A4 to D4 = 1,2,3,6 A5 to D5 = 1,2,4,5 A6 to D6 = 1,2,4,6 .. .. .. An to Dn = 1,4,5,6 .. .. .. Ax to Dx = 3,4,5,6 Basically, the macro should create any four combination from the data. Thank you |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data series
It works great!
Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Time Series and Creating data points within a series | Excel Discussion (Misc queries) | |||
chart with two data series and two colors for each data series | Charts and Charting in Excel | |||
2nd Axes - primary series data of only 1 series disappears! | Charts and Charting in Excel | |||
how do I plot a data series against two series | Charts and Charting in Excel | |||
chart data series -- plot a table as a single series | Charts and Charting in Excel |