Macro To Create Sheet with Consecutive Letter Strings

Toby123

New Member
Joined
Sep 6, 2023
Messages
20
Office Version
  1. 365
Platform
  1. MacOS
Hello!

I am looking for a sheet with consecutive 6 letter strings, using all the letters of the alphabet except a, e, i, o, u, x and z. It would start with bbbbbb, bbbbbc, bbbbbd, then when it reaches bbbbbz jump to bbbbcb, bbbbcc, bbbbcd etc. It should end at yyyyyy. This should give 47,045,881 (19^6) combinations by my reckoning. If it is easier we could run it with all the letters then search and remove the cells containing the unwanted letters afterwards. I presume a macro would be the best way of doing this. Thank you in advance!
 
How about
VBA Code:
Sub Toby()
   Dim Ary(1 To 50000, 1 To 1) As Variant, Lts As Variant
   Dim i As Long, j As Long, k As Long, l As Long, m As Long, n As Long
   Dim nr As Long, nc As Long
 
   Lts = Split("b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,y", ",")
   nc = 1
   Application.ScreenUpdating = False
   For i = 0 To 18
      For j = 0 To 18
         For k = 0 To 18
            For l = 0 To 18
               For m = 0 To 18
                  For n = 0 To 18
                     nr = nr + 1
                     Ary(nr, 1) = Lts(i) & Lts(j) & Lts(k) & Lts(l) & Lts(m) & Lts(n)
                     If nr = 50000 Then
                        Cells(1, nc).Resize(50000).Value = Ary
                        nc = nc + 1
                        nr = 0
                     End If
                  Next n
               Next m
            Next l
         Next k
      Next j
   Next i
   Cells(1, nc).Resize(nr).Value = Ary
End Sub
It worked like a dream, completed in about 8 minutes, thank you so much!
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,215,123
Messages
6,123,182
Members
449,090
Latest member
bes000

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