I need to find all the numbers with two 3s and two 7s in any order from a list of 65000 sequential numbers from 10000 to 65000 in the first column of a spreadsheet.
Here is the code so far:
Sub VBA_Loop_through_Rows()
Dim w As Range
Dim threeCount As Integer
Dim fourCount As Integer
For Each w In Range("A1001:AC70435").Rows
threeCount = 0
sevenCount = 0
If Left(w.Cells(1), 1) = "3" Then
threeCount = threeCount + 1
End If
If Left(w.Cells(1), 1) = "7" Then
sevenCount = sevenCount + 1
End If
If Left(w.Cells(1), 2) = "3" Then
threeCount = threeCount + 1
End If
If Left(w.Cells(1), 2) = "7" Then
sevenCount = sevenCount + 1
End If
If Left(w.Cells(1), 3) = "3" Then
threeCount = threeCount + 1
End If
If Left(w.Cells(1), 3) = "7" Then
sevenCount = sevenCount + 1
End If
If Left(w.Cells(1), 4) = "3" Then
threeCount = threeCount + 1
End If
If Left(w.Cells(1), 4) = "7" Then
sevenCount = sevenCount + 1
End If
If Left(w.Cells(1), 5) = "3" Then
threeCount = threeCount + 1
End If
If Left(w.Cells(1), 5) = "7" Then
sevenCount = sevenCount + 1
End If
If threeCount > 1 Then
Debug.Print w.Cells(1)
Debug.Print threeCount
Debug.Print sevenCount
End If
Next
End Sub
This does not produce the right result. I think the problem is trying to manipulate a number with a string function. But changing the format in Excell from general to text does not solve the problem. Perhaps first dividing by 10,000 and truncating the result, then doing the same sort of reduction sequentially would help.