Home > OS >  is it possible to create 16M combinations in excel?
is it possible to create 16M combinations in excel?

Time:08-29

if I want to create an excel document with all the possible combinations of hex color codes( 16,772,216) is it possible? or is there another program that can help me with that?

thanks

CodePudding user response:

THe following creates 16 columns of Hex colour codes, including all possible codes. I tried to change each cell to the corresponding colour but there seems to be an excel limit on how many different colours you can use in a worksheet; so I have included a bit of code that converts whichever cell you select into that cell's colour. Not sure if either of these are what you wanted but hopefully they help.

Private l1, l2, l3, l4, l5, l6, lNum, lRow, lHexLong As Long
Private l1stDigit, l2ndDigit, l3rdDigit, l4thDigit, l5thDigit, l6thDigit, lDigit, lHex As String

    Sub mHex()
    
    For l1 = 1 To 16
        lRow = 1
        lNum = l1
        fBase16
        l1stDigit = lDigit
        For l2 = 1 To 16
            lNum = l2
            fBase16
            l2ndDigit = lDigit
            For l3 = 1 To 16
                lNum = l3
                fBase16
                l3rdDigit = lDigit
                For l4 = 1 To 16
                    lNum = l4
                    fBase16
                    l4thDigit = lDigit
                    For l5 = 1 To 16
                        lNum = l5
                        fBase16
                        l5thDigit = lDigit
                        For l6 = 1 To 16
                            lNum = l6
                            fBase16
                            l6thDigit = lDigit
                            lHex = "#" & l1stDigit & l2ndDigit & l3rdDigit & l4thDigit & l5thDigit & l6thDigit
                            Cells(lRow, l1).Value = lHex
                            lRow = lRow   1
                        Next
                    Next
                Next
            Next
            MsgBox (Time())
        Next
    Next
            
    End Sub
    Sub CellColour()
    lHex = ActiveCell.Value
    lHexLong = Application.WorksheetFunction.Hex2Dec(Mid(lHex, 6, 2) & Mid(lHex, 4, 2) & Mid(lHex, 2, 2))
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = lHexLong
        .TintAndShade = 0
        .PatternTintAndShade = 0
     End With
    End Sub
    Function fBase16()
    Select Case lNum
            Case 1
            lDigit = "0"
            Case 2
            lDigit = "1"
            Case 3
            lDigit = "2"
            Case 4
            lDigit = "3"
            Case 5
            lDigit = "4"
            Case 6
            lDigit = "5"
            Case 7
            lDigit = "6"
            Case 8
            lDigit = "7"
            Case 9
            lDigit = "8"
            Case 10
            lDigit = "9"
            Case 11
            lDigit = "A"
            Case 12
            lDigit = "B"
            Case 13
            lDigit = "C"
            Case 14
            lDigit = "D"
            Case 15
            lDigit = "E"
            Case 16
            lDigit = "F"
            End Select
    End Function

CodePudding user response:

This formula in Excel365 will give you 16.772.216 million HEX-Codes in 16 columns and 1.048.264 rows

=DEC2HEX(SEQUENCE(1048264;16))

Excel will calculate a moment ;-)

  • Related