Hi. Your code took 58 Seconds for me.
The following did it in 25 Seconds.
This is just 1 of many other ideas. There are 11 Integer Partitions of the
number 6, as your Map() variable holds. I took the Permutations of each
pattern, for a total of 32 possible patterns (0's removed). The idea was to
remove the Sort.
This is still not efficient because I'm still counting A,B,C...on each loop,
although they don't change as fast. I'm tried to change the count of each
variable A,B,C...etc as each variable changes, but I'm having a hard time
with the logic.
Note that there are 3003 possible patterns if we keep the 0's in the count
array. This is easy in other programs, but a little hard to do with Excel.
Anyway, here's my first attempt.
Option Explicit
Sub First_Digit_v2()
Dim A As Integer, B As Integer, C As Integer
Dim D As Integer, E As Integer, F As Integer
Dim n As Long
Dim x As Long
Dim y As Long
Dim Tme As Double 'For Start Time
Dim pIn As Variant 'Pattern In
Dim pOut As Variant 'Pattern Out
Dim P(1 To 11) As Long 'Count of Patterns
Dim M(1 To 49) As Long 'First Digits (1-49)
Dim T(1 To 9) As Long 'Count of Digits(1-9)
Dim Dic 'Dictionary Object
Set Dic = CreateObject("Scripting.Dictionary")
Tme = Timer
'// Build Lookup Table
'// Pattern Input
pIn = Array( _
6, 51, 15, 42, 24, 411, 141, _
114, 33, 321, 312, 231, 213, 132, 123, 3111, _
1311, 1131, 1113, 222, 2211, 2121, 2112, 1221, _
1212, 1122, 21111, 12111, 11211, 11121, 11112, 111111)
'// Pattern Output
pOut = Array( _
11, 10, 10, 9, 9, 8, 8, 8, 7, 6, 6, 6, 6, 6, 6, _
5, 5, 5, 5, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1)
For n = 1 To 32
Dic.Add pIn(n - 1), pOut(n - 1)
Next n
'// Load First Digits
For n = 1 To 49
If n <= 9 Then
M(n) = n
Else
M(n) = n \ 10
End If
Next n
For A = 1 To 44
For B = A + 1 To 45
For C = B + 1 To 46
For D = C + 1 To 47
For E = D + 1 To 48
For F = E + 1 To 49
Erase T
T(M(A)) = 1
T(M(B)) = T(M(B)) + 1
T(M(C)) = T(M(C)) + 1
T(M(D)) = T(M(D)) + 1
T(M(E)) = T(M(E)) + 1
T(M(F)) = T(M(F)) + 1
x = 0
For n = 1 To 9
If T(n) > 0 Then x = x * 10 + T(n)
Next n
y = Dic(x)
P(y) = P(y) + 1
Next F, E, D, C, B, A
For n = 1 To 11
Cells(n, 3) = P(n)
Next
Debug.Print Timer - Tme
End Sub