combination of 2 letters

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,

try this code. if it helps

VBA Code:
Sub MakeValues()
    Dim d As Object
    Dim i As Long, j As Long
    Dim strNbr As String
    Dim lngChoices As Long
    Dim mykeys
    Dim strChoice As String
    Dim lngPossibles As Long
    'change these input box inputs to pull directly from spreadsheet
    'if desired.
    strNbr = Range("A1").Value
    lngChoices = 3
 
    Set d = CreateObject("Scripting.Dictionary")
 
    'find out which digits are being used: get unique list
    For i = 1 To Len(Trim(strNbr))
        If Not d.exists(Mid(Trim(strNbr), i, 1)) Then
            d.Add Mid(Trim(strNbr), i, 1), ""
        End If
    Next i
 
    'mykeys is an array containing the unique values to
    'get the combo's from
    mykeys = d.keys()
 
    Range("C:C").Clear
    'hopefully we don't blow out the max size of i
    'of course, if we do, we won't be able to
    'output to a single column anyway :)
    lngPossibles = d.Count
    For i = 0 To (lngPossibles) ^ lngChoices - 1
        strChoice = ""
        For j = lngChoices - 1 To 0 Step -1
            strChoice = strChoice & mykeys(Int(i / (lngPossibles ^ j)) Mod lngPossibles)
        Next j
        'change i+1 to i+x to start inputing in row x
        Cells(i + 1, 3).NumberFormat = "@"
        Cells(i + 1, 3) = strChoice
    Next i
    Set d = Nothing
End Sub
 
Upvote 0
Solution
Here is a general solution:
MrExcelPlayground.xlsm
ABCDE
11248
20SSSS
31TSSS
42STSS
53TTSS
64SSTS
75TSTS
86STTS
97TTTS
108SSST
119TSST
1210STST
1311TTST
1412SSTT
1513TSTT
1614STTT
1715TTTT
Sheet26
Cell Formulas
RangeFormula
B2:E17B2=IF(BITAND($A2,B$1)=0,"S","T")


And a more compact specific solution:
MrExcelPlayground.xlsm
GH
20SSS
31TSS
42STS
53TTS
64SST
75TST
86STT
97TTT
Sheet26
Cell Formulas
RangeFormula
H2:H9H2=IF(BITAND($A2,1)=0,"S","T")&IF(BITAND($A2,2)=0,"S","T")&IF(BITAND($A2,4)=0,"S","T")
 
Upvote 0
Hi,

try this code. if it helps

VBA Code:
Sub MakeValues()
    Dim d As Object
    Dim i As Long, j As Long
    Dim strNbr As String
    Dim lngChoices As Long
    Dim mykeys
    Dim strChoice As String
    Dim lngPossibles As Long
    'change these input box inputs to pull directly from spreadsheet
    'if desired.
    strNbr = Range("A1").Value
    lngChoices = 3

    Set d = CreateObject("Scripting.Dictionary")

    'find out which digits are being used: get unique list
    For i = 1 To Len(Trim(strNbr))
        If Not d.exists(Mid(Trim(strNbr), i, 1)) Then
            d.Add Mid(Trim(strNbr), i, 1), ""
        End If
    Next i

    'mykeys is an array containing the unique values to
    'get the combo's from
    mykeys = d.keys()

    Range("C:C").Clear
    'hopefully we don't blow out the max size of i
    'of course, if we do, we won't be able to
    'output to a single column anyway :)
    lngPossibles = d.Count
    For i = 0 To (lngPossibles) ^ lngChoices - 1
        strChoice = ""
        For j = lngChoices - 1 To 0 Step -1
            strChoice = strChoice & mykeys(Int(i / (lngPossibles ^ j)) Mod lngPossibles)
        Next j
        'change i+1 to i+x to start inputing in row x
        Cells(i + 1, 3).NumberFormat = "@"
        Cells(i + 1, 3) = strChoice
    Next i
    Set d = Nothing
End Sub
Thank You hrayani

The code works like magic​

 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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