0

I am trying to use VBA in Excel to write all of the possible combinations of the contents of three arrays to a column to create a wordlist.

Currently, I know how to loop through the arrays and get some output that I want but I can't figure out how to build the loop to give me all possible combinations of the baseWord(n) & numberCharSet(n) & specialCharSet(n).

How do I properly loop through the baseWord array to get all combinations of each baseWord with the contents of the specialCharSet and numberCharSet arrays?

Example: Cloud1! Cloud1@ Cloud1# Cloud1$ Cloud2! etc...

Private Sub createWordlist()

Dim baseWord(1 To 2) As String
baseWord(1) = "Cloud"
baseWord(2) = "cloud"

Dim numberCharSet(1 To 4) As String
numberCharSet(1) = "1"
numberCharSet(2) = "2"
numberCharSet(3) = "3"
numberCharSet(4) = "4"


Dim specialCharSet(1 To 4) As String
specialCharSet(1) = "!"
specialCharSet(2) = "@"
specialCharSet(3) = "#"
specialCharSet(4) = "$"

x = 1
y = 1
z = 4
w = 1

For Each Item In baseWord
    Range("A" & x).Value = baseWord(w) & numberCharSet(y) & specialCharSet(z)
    x = x + 1
    y = y + 1
    z = z - 1
Next

End Sub
1
  • 1
    You need three nested loops one for each array. Commented Sep 14, 2016 at 18:26

1 Answer 1

2

As @ScottCraner mentioned in the comments, all you need to do is nest 3 loops:

For Each word In baseWord
    For Each num In numberCharSet
        For Each special In specialCharSet
            Debug.Print word & num & special
        Next
    Next
Next
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.