I'm using Excel and am trying to generate a table (3 columns) that presents all possible combinations of the numbers 0,1,2,3,4,5, and 6. Digits are allowed to be repeated (example, 2-2-5). To do that manually it will take forever and frankly speaking, I'm not an expert here and was not able to solve this by my own.
In other words, each row would have three digits each placed on a separate cell; but three of them represent one possible combination of the digits 0-6. I need to have all the possible combinations. I have been looking allot for this but unfortunately couldn't.
Answer
This small macro will get your data:
Sub qwerty()
For i = 0 To 6
For j = 0 To 6
For k = 0 To 6
LL = LL + 1
Cells(LL, 1) = i
Cells(LL, 2) = j
Cells(LL, 3) = k
Next k
Next j
Next i
End Sub
Macros are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I ALT-M opens a fresh module
- paste the stuff in and close the VBE window
If you save the workbook, the macro will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
To remove the macro:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the macro from Excel:
- ALT-F8
- Select the macro
- Touch RUN
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
Macros must be enabled for this to work!
No comments:
Post a Comment