rwmill9716
Active Member
- Joined
- May 20, 2006
- Messages
- 493
- Office Version
- 2013
- Platform
- Windows
Range("F1").Resize(UBound(c, 1), UBound(c, 2)).Value = c
ReDim b(1 To UBound(a, 1), 1 To 1000) 'times
Sub rand_word_v2()
Dim a As Variant, b As Variant, c As Variant, arr As Variant
Dim i&, j&, k&, lr&, n&, m&, x&, y&, z&
Dim w1 As String, w2 As String, w3 As String
Randomize
a = Range("A1", Range("A" & Rows.Count).End(3)).Value
ReDim b(1 To UBound(a, 1), 1 To 1000) 'times
ReDim c(1 To UBound(b, 1), 1 To UBound(b, 2))
With Range("C1")
w1 = LCase(Mid(.Text, 1, 1))
w2 = LCase(Mid(.Text, 2, 1))
w3 = LCase(Mid(.Text, 3, 1))
End With
For j = 1 To UBound(b, 2)
arr = Evaluate("ROW(1:" & UBound(a, 1) & ")") 'total records
lr = UBound(a, 1)
For z = 1 To UBound(a) 'how many do i want
x = Int(Rnd * lr + z)
y = arr(z, 1)
arr(z, 1) = arr(x, 1)
arr(x, 1) = y
lr = lr - 1
m = arr(z, 1) 'random number
b(z, j) = a(m, 1)
Next
For i = 3 To UBound(b, 1)
If LCase(b(i - 2, j)) = w1 And LCase(b(i - 1, j)) = w2 And LCase(b(i, j)) = w3 Then
k = k + 1
For n = 1 To UBound(b, 1)
c(n, k) = b(n, j)
Next
End If
Next
Next
Range("D1").Value = k
Range("F1").Resize(UBound(c, 1), UBound(c, 2)).Value = c
End Sub
Dante,Try the following macro.
The result of the count in cell D1.
From column F onwards the matches.
View attachment 97919
NOTES:
1. It works for 3 letters in cell D1.2. If you don't want the result columns, remove this line from the macro:Range("F1").Resize(UBound(c, 1), UBound(c, 2)).Value = c
3. Set the number of times in this line of the macro:ReDim b(1 To UBound(a, 1), 1 To 1000) 'times
Put the following code in a module:
VBA Code:Sub rand_word_v2() Dim a As Variant, b As Variant, c As Variant, arr As Variant Dim i&, j&, k&, lr&, n&, m&, x&, y&, z& Dim w1 As String, w2 As String, w3 As String Randomize a = Range("A1", Range("A" & Rows.Count).End(3)).Value ReDim b(1 To UBound(a, 1), 1 To 1000) 'times ReDim c(1 To UBound(b, 1), 1 To UBound(b, 2)) With Range("C1") w1 = LCase(Mid(.Text, 1, 1)) w2 = LCase(Mid(.Text, 2, 1)) w3 = LCase(Mid(.Text, 3, 1)) End With For j = 1 To UBound(b, 2) arr = Evaluate("ROW(1:" & UBound(a, 1) & ")") 'total records lr = UBound(a, 1) For z = 1 To UBound(a) 'how many do i want x = Int(Rnd * lr + z) y = arr(z, 1) arr(z, 1) = arr(x, 1) arr(x, 1) = y lr = lr - 1 m = arr(z, 1) 'random number b(z, j) = a(m, 1) Next For i = 3 To UBound(b, 1) If LCase(b(i - 2, j)) = w1 And LCase(b(i - 1, j)) = w2 And LCase(b(i, j)) = w3 Then k = k + 1 For n = 1 To UBound(b, 1) c(n, k) = b(n, j) Next End If Next Next Range("D1").Value = k Range("F1").Resize(UBound(c, 1), UBound(c, 2)).Value = c End Sub
--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------
So I didn't understand your requirement.1. The rearrangements of column A don't appear to be random, i.e., it's not possible for "Ric" to show up in each column.
2. What I want is column A to be 10,000 rows (192 complete sets of 26 letters alphabet) {of course, the program development can be much smaller}.
3. That complete column is then randomized; it's ok to put the randomized column in another column.
4. The letter sequence in cell C1 is searched for in the randomized column, and the number of times it occurs is output in D1.
5. Here, I show a 3-letter sequence, but I would like to be able to change that to other length words.
230209 Sequencing Share.xlsm | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
1 | Letters | =RAND() | =CONCATENATE(A2,A3,A4) | =CONCATENATE(A4,A3,A2) | =IF(OR(F$1=C2,G$1=D2),1,0) | RIC | CIR | Results | |||
2 | F | 0.56356 | FLL | LLF | 0 | 0 | 0 | ||||
3 | L | 0.94582 | LLO | OLL | 0 | 0 | |||||
4 | L | 0.00596 | LOC | COL | 0 | 1 | |||||
5 | O | 0.04993 | OCF | FCO | 0 | 2 | |||||
6 | C | 0.79065 | CFA | AFC | 0 | 0 | |||||
7 | F | 0.86092 | FAG | GAF | 0 | 0 | |||||
8 | A | 0.19480 | AGP | PGA | 0 | 0 | |||||
9 | G | 0.58370 | GP | PG | 0 | 0 | |||||
10 | P | 0.33145 | P | P | 0 | 1 | |||||
11 | 1 | ||||||||||
12 | |||||||||||
Word Probability |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B2:B10 | B2 | =RAND() |
C2:C10 | C2 | =CONCATENATE(A2,A3,A4) |
D2:D10 | D2 | =CONCATENATE(A4,A3,A2) |
E2:E10 | E2 | =IF(OR(F$1=C2,G$1=D2),1,0) |
F2 | F2 | =SUM(E2:E17) |
F3:F10 | F3 | =IF(E3=1,1,"") |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
E9:E10 | Cell Value | >0 | text | NO |
E1:E8,E11:E1048576 | Cell Value | >0 | text | NO |
F:F | Cell Value | >">0" | text | NO |
Excel 2013That still does not tell us what Excel version you are using. Refer to post #5
Thanks. Can you now put it in your account details so that it is always readily available for helpers to refer to like this?Excel 2013
Ultimately, I'm using this program to study word sequences (codes if you will) that occur in the Bible (validated by fulfilled prophecy, scientific facts, and hidden codes). These codes can have words that are written both ways depending on whether the name is being favorably or unfavorably looked at. The codes are there (usually with much longer words), and I want to get a feel for just how rare there occurrences are).Thanks. Can you now put it in your account details so that it is always readily available for helpers to refer to like this?
View attachment 97962
A bit more clarification about your question.
- If this is about word occurrences, why check the reverse of the word as well as the word itself since the reverse is unlikely to be an actual word? That is, why check "RIC" and "CIR"?
- If you have 10,000 rows of letters, it is possible (likely) that a word (&/or its reverse) will occur multiple times. So in a particular recalculation if "RIC" occurred 3 times and "CIR" occurred 2 times, can you clarify what value should appear in the results column for that row?